git - 存储弹出期间合并冲突后出现错误
原标题:git - 更新所有未更改的文件
目前我正在尝试更新 git 存储库中所有未更改的文件。比方说,我有:
- test1.py
- test2.py
test1.py 已在本地修改,而两个文件已被远程修改。现在我尝试:
git stash
git pull
git stash pop
它恢复了我的更改,并警告我需要合并 test1.py
。到目前为止,一切都很好。当我尝试再次执行相同的过程时(在两个文件再次远程更改之后),问题就出现了。 Git 现在说
unmerged (6b126638f7c63aa648609afa60ab972a2403502b)
fatal: git-write-tree: error building trees
Cannot save the current index state
这让我有点难过。它只想要一件简单的事情:更新所有我没有更改的文件。稍后我会负责合并。
Original title: git - update all files that have not been changed
Currently I am trying to update all files in a git repository that have not been changed. Lets say for example I have:
- test1.py
- test2.py
test1.py has been modified locally while both files have been modified remotely. Now I tried:
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
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您解决了文件中的冲突(也许?请参阅脚注),但 Git 不知道您是否已完成。您必须向 git 表明您已经解决了该冲突。 (否则,如果它让你继续前进而你实际上没有解决它,你可能会想尽各种办法搬起石头砸自己的脚。)
据我所知,这样做的方法是:
似乎有应该是一种使用
update-index
同时执行这两项操作的方法,但快速浏览一下,这对我来说并不明显。 (但话又说回来,对于实际的合并冲突,您永远不想在不暂存内容的情况下将冲突标记为已解决;这只是为了存储而出现。)正如 VonC 在他的回答中所说,这应该再次发生时,您可以使用 git status 轻松查看哪些内容在应用存储时发生了合并冲突。它们将以红色列出(如果您有颜色),并显示
未合并
(或者如果是删除/修改冲突,则可能被我们/他们删除
)。脚注:回顾你的问题,我实际上无法判断你是否解决了冲突 - 你只是说“到目前为止一切都很好”。您看到的“警告”实际上是建议立即解决冲突。当试图将您拉出的更改与您隐藏的更改结合起来时,就会出现冲突。在以任何方式继续之前,您必须解决该冲突并使您的工作树进入一致状态。就像处理合并冲突一样处理它 - 查看文件,找到冲突标记,找出要保留的内容! (然后回顾上面如何完成。)
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.)
As far as I know, the way to do that is:
It seems like there should be a way to do both at once with
update-index
but it's not obvious to me from a quick look. (But then again, for actual merge conflicts, you never want to mark a conflict as resolved without staging the content; it's just for stashes that this arises.)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 sayunmerged
(or maybedeleted by us/them
if it was a delete/modify conflict).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.)
这应该意味着您的第二个存储由于仍未解决的合并而无法工作。
请参阅这个SO问题,它说明了存储中的相同错误消息。
此线程确认树不能包含未合并的文件。
That should mean your second stash don't work because of still unresolved merge.
See this SO question which illustrates the same error message on a stash.
This thread confirms that a tree cannot contain unmerged files.