包含在.gitignore中的消失文件 [英] Vanishing file included in .gitignore

查看:229
本文介绍了包含在.gitignore中的消失文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是天真的问题:

我将文件config.yml放在.gitignore文件中
当我将分支切换到'someotherbranch'然后我切换回主人



然后我没有看到config.yml



为什么忽略的文件是在切换分支后消失,我能做些什么来避免它? 解析方案

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

假设你添加一个'ignored'文件,提交它,然后创建两个分支'normalbranch'和'removedbranch'。然后,添加一个.gitignore,并在'normal'分支中忽略该文件,并在'ignore'分支中删除该文件。



此时,如果将removedbranch合并到normalbranch中,git将删除文件'ignored',而不管'ignore'设置如何。或者简单地说:只有 git status 关心'.ignored'文件。



您可以使用 git rm --cached< file> 从所有分支中删除该文件,以将其从混帐没有删除实际的文件。在这一点之后,一切都应该照常进行。



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

干杯,
Reto


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?

解决方案

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

这篇关于包含在.gitignore中的消失文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆