git pull 失败并显示“未跟踪的工作树文件‘blah’将被合并覆盖”,但树是干净的

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3165696/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 08:40:15  来源:igfitidea点击:

git pull fails with "Untracked working tree file 'blah' would be overwritten by merge", but tree is clean

git

提问by Paul Butcher

I've checked in some changes to my local repository that I want to push, but when I do a git pull, I get:

我已经检查了我想要推送的本地存储库的一些更改,但是当我执行 git pull 时,我得到:

paul$ git pull 

error: Untracked working tree file 'documentation/Android/SwiftKey/buttons.xcf' would be overwritten by merge. Aborting

错误:未跟踪的工作树文件“documentation/Android/SwiftKey/buttons.xcf”将被合并覆盖。中止

My working tree contains no untracked files:

我的工作树不包含未跟踪的文件:

paul$ git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 2 and 26 different commit(s) each, respectively.
#
nothing to commit (working directory clean)

The commits that I've made do not touch the file that it's complaining about.

我所做的提交没有触及它抱怨的文件。

I've read answers suggesting that I do a git reset HEAD --hard, but I'm not sure what effect that will have on the commits that I've made?

我已经阅读了建议我做 a 的答案git reset HEAD --hard,但我不确定这会对我所做的提交产生什么影响?

采纳答案by Neil Mayhew

It's not the commits you've made that touch the file, but the commits that you're pulling. Inspect the remote branch you're tracking to see what's happened. For example, git log master..origin/masterwill show all the commits that have happened on origin/mastersince you last pulled. According to your output above, there are 26 of these. Using the --name-statusoption will show which commit added the file.

影响文件的不是您所做的提交,而是您正在提取的提交。检查您正在跟踪的远程分支以查看发生了什么。例如,git log master..origin/master将显示自上次拉取以来在origin/master上发生的所有提交。根据您上面的输出,其中有 26 个。使用该--name-status选项将显示添加了文件的提交。

You will need to rename the offending file, do the pull, and then move it back (overwriting the copy from the repo). git diff filenamewill then tell you how your copy differs from the one that someone else has committed to master. You can then commit the differences, or throw them away with git checkout filename.

您需要重命名有问题的文件,执行拉取操作,然后将其移回(覆盖存储库中的副本)。然后会告诉您您的副本与其他人承诺要掌握的副本有何不同。然后,您可以提交差异,或者使用.git diff filenamegit checkout filename

You will need to use git pull --rebaseto rebase your recent commits on top of the ones in origin. Once git statussays master is aheadrather than divergedfrom origin/master, you can push.

您将需要使用git pull --rebase将您最近的提交重新绑定到origin. 一旦git status说 master领先而不是偏离origin/master,您就可以推动。