Git is deleting an ignored file when i switch branches

前端 未结 5 867
你的背包
你的背包 2020-11-27 18:16

I have one branch (let\'s call it B) that ignores a certain file, which isn\'t ignored in some other branches (eg branch A). When i switch from branch B to branch

5条回答
  •  天涯浪人
    2020-11-27 19:03

    It's normal, though I'm a little surprised by one step of it.

    When you switch from B to A, git sees that the file must be updated to match A's version, and does so silently because you've ignored it, saying that as far as branch B is concerned, the file doesn't matter. It has to do this - the only alternative is to refuse to check out branch A. (It would refuse if the file weren't ignored, saying "Untracked working tree file '' would be overwritten by merge". I'm actually surprised it doesn't do that in this case too. Anyone have any insight as to whether that's feature or bug?)

    When you switch back to, git sees that branch B doesn't have that file, and removes it. Again, it has to do this. It has no way to read your mind and realize that that ignored file that was there a minute ago is one you want back - it simply gives you the contents of branch B, which state that the file doesn't exist.

    As ewall suggests in the comments, if you want the file to survive these transitions, it needs to be tracked by all branches, or ignored in all branches.

提交回复
热议问题