Vanishing file included in .gitignore

时光毁灭记忆、已成空白 提交于 2019-12-06 11:17:20

问题


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?


回答1:


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




回答2:


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'



来源:https://stackoverflow.com/questions/3606974/vanishing-file-included-in-gitignore

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!