I have committed a big merge. Later, it appears that some files weren\'t merged correctly. I want to redo just these files, not the entire merge - the merge was big and I do
You can, in fact, simply perform the merge again. (Be sure you have git rerere
turned off.)
Remember, git merge
looks at three things: your current commit, the commit you ask it to merge, and the merge-base of those two commits. (Well, also your strategy arguments and so on, of course, but you can repeat those as well.) It's true that you already committed a merge result, but you can still get back on the commit you were on earlier:
o---o---X <-- otherbranch
/ \
...--o--* \
\ \
o--o--o--Y--M <-- HEAD -> yourbranch
Your merge M
is the result of merging commits Y
and X
(with merge base *
). But you can check out commit Y
as either a detached HEAD or a new branch. To make a new branch:
git checkout -b newbranch yourbranch^
which produces:
o---o----X <-- otherbranch
/ \
...--o--* M <-- yourbranch
\ /
o--o--o--Y <-- HEAD -> newbranch
(this is the exact same graph but I moved M
up a bit to make room for newbranch
to point to commit Y
—think of the graph as being kind of rubbery/stretchy, or printed on Play-Doh®, or whatever). Now you can git merge otherbranch
and start re-creating commit M
.
Now you can grab merge results (rather than re-resolving) using git checkout yourbranch -- path
for various path
s (even the top path), and optionally git checkout -m
parts to re-create conflicts.
When you are all done, git commit
will make a new M2
merge whose first parent is Y
and second parent is X
, and newbranch
will point to the new merge M2
.