Reputation: 27365
Is there a way to commit an incomplete merge? I've resolved half the conflicts. The other half my colleague is much better qualified to deal with.
Perhaps equally good, or even better, would be to take conflict chunks and restore them to files in a conflicted state. Then I could commit the merge with the conflict chunks and my colleague could grab it, return the files to a "conflict" state, and take it from there.
Upvotes: 3
Views: 1125
Reputation: 490068
The short answer is no, it's not possible.
I've been meaning to work on a script to get as close as one could. During conflict resolution, there are three copies of each file in the index, plus a fourth in the work-tree. (Add in the unchangeable copy in HEAD
and there are, in effect, five active copies of every file—but we need only save four of them, since the one in HEAD
cannot be changed.) It would be possible to save each of these in a way very similar to what git stash
does, which would enable transferring the "stashed in-progress merge" via the usual Git mechanisms.1 This would cover most cases. However, there's some special information in the index during a partially-resolved merge—the "REUC" undo entries—that cannot be preserved at all, and all merges fail to record some important information about high-level conflicts (rename/rename conflicts for instance) that really should be exposed somehow before doing this.
If you don't need the undo entries, this script I didn't write might do the trick, but alas, I haven't written it. :-) The fundamental idea, though, is to read/copy the current (merge-conflicted) index into three or four unconflicted temporary index copies: one for every stage-1 entry, one for every stage-2 entry, and one for every stage-3 entry. We also need one for all stage-0 entries though perhaps the original index can be used here. Add one last temporary index to hold the actual work-tree state w
, complete with files with conflict-markers in them (and maybe a u
commit for untracked files in case someone is using git mergetool
?). Make commits from all the temporary index files, tying them together in some useful way and to the HEAD
commit the same way that git stash
makes a stash-bag out of its i
and w
commits. Then, do git reset --hard
, the same way that git stash
does.
To restore the conflicted state, start by making sure everything is clean, then read each of the commits into a temporary index. Use the resulting index files to build a new conflicted index, with entries at stages 0, 1, 2, and 3 as appropriate. Use the work-tree commit to establish the work-tree state from the saved-merge w
commit (probably do that first, actually).
1It's technically possible to transport git stash
commits between repositories today, but the git stash
front-end and inner workings make it a bit tricky. Since the, or at least a, point of this script would be to make it easy to transport an in-progress merge, whatever script one comes up with needs to provide a mechanism and some clear instructions for doing this.
Upvotes: 1