开发者

Vanishing file included in .gitignore

this is probably naive question:

i have file config.yml which is in .gitignore file when I'm s开发者_开发技巧witching 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?


Files which are tracked AND ignored are treated like normal files. This usually happens if you ignore the files after you've added them.

Lets say you add a file 'ignored', commit it, then create two branches 'normalbranch' and 'removedbranch'. Then you add a .gitignore with the file ignored in the 'normal' branch and remove the file in the 'ignore' branch.

At this point, if you merge removedbranch into normalbranch git will remove the file 'ignored', regardless the 'ignore' setting. Or to put it short: only git status cares about '.ignored' files.

You could remove the file from all branches with git rm --cached <file> to remove it from git without remove the actual file. After this point everything should work as usual

This is btw. the way to ignore a file which is currently tracked.

Cheers, Reto


if the file exists in the second branch it will be deleted when you switch back.

make sure the file does not exist in 'someotherbranch'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜