【发布时间】:2010-12-25 14:45:58
【问题描述】:
我被 git 新手似乎很常见的问题所吸引。
我忘了 .gitignore 一个特定的文件,并且在提交后将它添加到 .gitignore 没有任何区别。
我找到了this page on gitready,它解释了如何从存储库中删除文件而不将其从工作树中删除(通过使用命令git rm --cached <file>,它工作正常,除非我尝试将其合并回另一个分支,工作树中的文件被删除。
复制步骤,在一个空文件夹中:
git init
touch want.txt
touch wantnot.txt
git add .
git commit -m "Initial"
git checkout -b BranchForIgnore
git rm --cached wantnot.txt
cat > .gitignore
wantnot.txt [Ctrl-D Ctrl-D here to exit cat]
git add .
git commit -m "Ignoring file"
到这里为止,一切都很好
git checkout master
git merge BranchForIgnore
此时,我的 wantnot.txt 文件已不在我的 master 中,显然,检查 BranchForIgnore 也无济于事。
怎么办?
【问题讨论】:
标签: git