我遇到过这个问题好几次了,但我还没有找到答案。如果结果是重复的,我们深表歉意。
假设我有以下三个提交: A——B——C (在每次提交中都添加了新文件)。
有时我想编辑提交 A,所以我 rebase -i
并将 A 标记为编辑。不幸的是,我使用 Sublime 作为我的编辑器,我在编辑 A 时错误地保存了一个在 C 中提交的文件(比如 file.cpp)。在执行 git status
后,现在有一个未跟踪的文件, 正如预期的那样。
现在,一旦我对 A 进行了我想要的编辑,我就忘记了未跟踪的文件并执行 git rebase --continue
。到达提交 C 后,我收到错误
error: The following untracked working tree files would be overwritten by merge:
file.cpp
此时我该怎么办?我试过 git stash
,然后是 git rebase --continue
,但现在我以 A -- B 提交而不是 A -- B -- C 结束。
谢谢。
最佳答案
找到这样的文件后,您将在应用新提交之前离开。 git stash
什么都不做,因为唯一剩下的就是那个未跟踪的文件。
然后你可以 git add file.cpp
, git stash
, git rebase --continue
, git stash pop
一切都会好起来的。刚刚用 2.18 测试过。
关于git - 使用不需要的未跟踪文件重新定位。错误 merge ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51525271/