I have two branches: feature
and master
. I did a merge via:
$ git checkout feature
$ git merge master -Xdiff-algorithm=patience
This generated some Unmerged paths
. I resolved some of them.
Then, a new commit was pushed to master
. It will make the remaining merge conflict smaller, so I'd like to pull it in to my current merge.
How can I do this without losing my current resolutions?
I tried running git merge master
a second time, but it understandably declined with the message:
$ git merge master
error: Merging is not possible because you have unmerged files.
Edit: Maybe rerere
would help.
The short answer—"you can't"—is incredibly unsatisfying, but fortunately not quite true either.
The longer answer is ugly but workable: git add
the remaining unmerged files anyway, so that Git believes that the correct merge result is what you have now. Then commit the merge and save its hash ID somewhere, e.g., in a branch or tag name. (I tend to use a lightweight tag for this.) Then reset the merge away:
git add ...
git commit
git tag keep
git reset --hard HEAD~1
Now start over. When you encounter an unmerged file and want to get the version you merged, use:
git show keep:path/to/merged > path/to/merged.previously
for instance. If the result is 100% correct, use it; if it's 90% correct, use the correct parts; etc.
Repeat for each file. When done, commit the merge as usual. Delete the saves-the-hash-ID name (e.g., git tag -d keep
) when ready.
It's not the best user interface, by any means, but it does work. The biggest drawback here is that you can't easily go back and see which files you really did resolve correctly. One way to deal with that is to add an extra file before committing the partial merge, listing which files you think are correctly merged. You can get that back right away with git show keep:MERGED.LIST
or whatever you named this file.
(If you can keep that information in your head, you don't need the extra file, of course.)
(The reason you have to resolve the unresolved files is that Git won't let you commit until you do. The git stash
command works by making commits, so it can't do anything either.)