问题描述
我在 Git-Extensions 中开始提交以将更改添加到文件 myfile
。然后我想我点击了我不想要的地方,现在我对 myfile
所做的任何更改都被 git 忽略了。我已经关闭了 git-extensions,并且只在 powershell 中运行。
如果我更改文件,git status
显示没有区别。但是如果我添加带有 git add myfile
的文件(尽管没有理由假设它没有被跟踪,但它在最后一次提交中被更改了),那么 git status
仍然没有显示它。如果我删除 .gitignore
,那么 .gitignore
将出现在 git status
中,但 myfile
仍然不会。
如果我更改远程文件并执行 git pull
,git 将确认我的本地文件:
error: Your local changes to the following files would be overwritten by merge:
myfile
Please commit your changes or stash them before you merge.
Aborting
Updating 09ad056..eef460f
但我无法提交(因为我无法添加)并且 git stash
不会隐藏 myfile
。我可以删除 myfile
然后 git pull
工作,但之后我就开始了:没有本地更改被确认。
我从未观察到这种行为,也无法重现。如何进一步调试并解决问题?
既然找到了解决方案:
解决方法
有两个不太公开的标志,assume-unchanged
和 skip-worktree
,可以在本地存储库中的文件上设置它们,并在本地版本控制中“隐藏”它们。
可以使用 git update-index
设置/取消设置这些标志,并且您可以使用 git ls-files -v
并检查每行开头的状态字母来发现具有一个(或两个)这些标志的文件.
来自我们在评论中的讨论:显然,某些操作在您的文件上设置了该标志。
您现在知道如何发现这些文件,以及如何取消设置该标志。
我不精通 Git-Extensions,您可能会找到一种从其 GUI 执行相同操作(设置/取消设置/列表)的方法。
This SO question 包含一个非常完整的参考 --assume-unchanged
:
# set the flag :
git update-index --assume-unchanged <file>
# unset the flag :
git update-index --no-assume-unchanged <file>
# check for lines where the status letter is in *lowercase* :
git ls-files -v
# using grep :
git ls-files -v | grep '^[a-z]'
--skip-worktree
使用类似的命令:
# set the flag :
git update-index --skip-worktree <file>
# unset the flag :
git update-index --no-skip-worktree <file>
# check for lines where the status letter is 'S' (or 's') :
git ls-files -v
# using grep :
git ls-files -v | grep '^[Ss]'
,
正如您已经发现的,在 git 和 Git 扩展中忽略文件更改的方法很少。