我有一个文件 abc.log (出于某种原因)在 git 中被跟踪,但我(也许愚蠢地)设置为 --skip-worktree 所以对它的更改不会显示在我对存储库的提交中。我想更改分支:
~ % git checkout master
error: Your local changes to the following files would be overwritten by checkout:
abc.log
Please commit your changes or stash them before you switch branches.
Aborting
然后我尝试刷新索引并强制结帐:
~ % git update-index --really-refresh
~ % git checkout master -f
error: Entry 'abc.log' not uptodate. Cannot merge.
但是, abc.log 在本地没有任何更改:
~ % git status
On branch xyz
Your branch is ahead of 'origin/xyz' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
在Undo git update-index --assume-unchanged <file>之后,我尝试再次将其设置为 no-skip-worktree。
~ % git update-index --no-skip-worktree --no-assume-unchanged abc.log
fatal: Unable to mark file dump.rbd
按照https://stackoverflow.com/a/42363882之类的建议,我看到它被 git 跟踪,目前设置为跳过工作树
~ % git ls-files -v | grep "S "
S abc.log
然而,仅仅寻找它并没有显示它
~ % git ls-files --error-unmatch abc.log
error: pathspec 'abc.log' did not match any file(s) known to git
Did you forget to 'git add'?
而且我无法按如下方式添加
~ % git add dump.rbd
fatal: pathspec 'abc.log' did not match any files