开发者

git - errors after merge conflicts during stash pop

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 ag开发者_如何学编程ain 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.


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:

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-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 say unmerged (or maybe deleted 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.)


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.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜