git - stash pop 期间合并冲突后的错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5996484/
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-19 05:29:01  来源:igfitidea点击:

git - errors after merge conflicts during stash pop

gitgit-stash

提问by ftiaronsem

Original title: git - update all files that have not been changed

原标题:git - 更新所有没有改变的文件

Currently I am trying to update all files in a git repository that have not been changed. Lets say for example I have:

目前我正在尝试更新 git 存储库中尚未更改的所有文件。比如说我有:

  • test1.py
  • test2.py
  • 测试1.py
  • 测试2.py

test1.py has been modified locally while both files have been modified remotely. Now I tried:

test1.py 已在本地修改,而两个文件均已远程修改。现在我试过:

git stash
git pull
git stash pop

which restored my changes, giving me a warning that I need to merge test1.py. So far so good. The problem arises when I try to do the same process again (after both files have been again changed remotly). Git now says

这恢复了我的更改,警告我需要合并test1.py。到现在为止还挺好。当我尝试再次执行相同的过程时出现问题(在两个文件再次远程更改后)。Git 现在说

unmerged (6b126638f7c63aa648609afa60ab972a2403502b)
fatal: git-write-tree: error building trees
Cannot save the current index state

which makes me kind of sad. It just want a simple thing: Update all files that I haven't changed. I will take care of merging later.

这让我有点难过。它只是想要一个简单的事情:更新所有我没有改变的文件。稍后我会负责合并。

回答by Cascabel

You resolved the conflict in your file (maybe? see footnote), but Git doesn't know whether you're done or not. You have to indicate to git that you've finished resolving that conflict. (Otherwise, if it let you move on and you hadn't actually resolved it, you could find all kinds of ways to shoot yourself in the foot.)

您解决了文件中的冲突(也许?请参阅脚注),但 Git 不知道您是否已完成。您必须向 git 表明您已完成解决该冲突。(否则,如果它让你继续前进而你没有真正解决它,你可以找到各种方法来射自己的脚。)

As far as I know, the way to do that is:

据我所知,这样做的方法是:

git add <file>        # stage the resolved version, which marks it as resolved
git reset HEAD <file> # unstage the changes, leaving the resolution just in the work tree

It seems like there should be a way to do both at once with update-indexbut it's not obvious to me from a quick look. (But then again, for actual merge conflicts, you neverwant to mark a conflict as resolved without staging the content; it's just for stashes that this arises.)

似乎应该有一种方法可以同时使用这两种方法,update-index但快速浏览对我来说并不明显。(但话又说回来,对于实际的合并冲突,您永远不想在不暂存内容的情况下将冲突标记为已解决;这只是为了隐藏。)

And as VonC says in his answer, should this happen again, you can easily see what things had merge conflicts when applying the stash using git status. They'll be listed in red (if you have color on) and say unmerged(or maybe deleted by us/themif it was a delete/modify conflict).

正如 VonC 在他的回答中所说,如果这种情况再次发生,您可以在使用git status. 它们将以红色列出(如果您有颜色)并说unmerged(或者可能deleted by us/them是删除/修改冲突)。

Footnote: Looking back at your question, I can't actually tell if you fixed the conflicts or not - you just said "so far so good." The "warning" you saw is really meant as a suggestion to resolve the conflicts immediately. The conflicts arose when trying to combine the changes which you pulled with the changes which you had stashed away. You have to resolve that conflict and get your work tree into a consistent state before you can move on in any way. Deal with it just as you would a merge conflict - look in the file, find the conflict markers, figure out what content to keep! (And then look back above for how to finish up.)

脚注:回顾您的问题,我实际上无法判断您是否解决了冲突 - 您只是说“到目前为止一切顺利”。您看到的“警告”实际上是建议立即解决冲突。当试图将您拉取的更改与您隐藏的更改结合起来时,就会出现冲突。您必须解决该冲突并使您的工作树处于一致状态,然后才能以任何方式继续前进。就像处理合并冲突一样处理它 - 查看文件,找到冲突标记,找出要保留的内容!(然后回头看看如何完成。)

回答by VonC

That should mean your second stash don't work because of still unresolved merge.
See this SO questionwhich illustrates the same error message on a stash.

这应该意味着您的第二个存储由于仍未解决的合并而不起作用。
请参阅此SO 问题,该问题说明了存储中的相同错误消息。

This thread confirmsthat a tree cannot contain unmerged files.

线程确认树不能包含未合并的文件。

You have a tree with unmerged entries.
Why don't you look into the issue and solve it?
A simple "git status" should show you what are the unmerged entries. A simple look at those files should show you conflict markers.

Resolve the issue, commit, continue.

您有一个未合并条目的树。
你为什么不研究这个问题并解决它?
一个简单的“ git status”应该会告诉你什么是未合并的条目。简单地查看这些文件应该会显示冲突标记。

解决问题,提交,继续。