2

this is probably naive question:

i have file config.yml which is in .gitignore file when I'm switching branch to 'someotherbranch' and next i switch back to master

then I don't see config.yml

why ignored files are vanishing after switching branch and what can I do to avoid it?

4

2 回答 2

3

被跟踪和忽略的文件被视为普通文件。如果您在添加文件后忽略这些文件,通常会发生这种情况。

假设您添加一个“忽略”文件,提交它,然后创建两个分支“normalbranch”和“removedbranch”。然后添加一个 .gitignore 文件,该文件在“正常”分支中被忽略,并在“忽略”分支中删除该文件。

此时,如果你将removedbranch 合并到normalbranch 中,git 将删除文件'ignored',而不管'ignore' 设置。或者简而言之:只git status关心“.ignored”文件。

您可以从所有分支中删除文件git rm --cached <file>以从 git 中删除它而不删除实际文件。在此之后,一切都应该照常工作

这是顺便说一句。忽略当前跟踪的文件的方法。

干杯,雷托

于 2010-08-31T07:52:32.623 回答
0

如果该文件存在于第二个分支中,则在您切换回来时它将被删除。

确保文件不存在于“someotherbranch”中

于 2010-08-31T07:51:44.637 回答