0

When two branches are merged and if there is conflict, after the conflict is resolved and committed, the change of this conflict resolution is recorded in the merge commit, as can be seen by git show. Now I need to cherry-pick just this conflict resolution, not the merge itself (which can be achieved by git cherry-pick -m). Is it possible?

The reason why I need to do this is, besides the diff in this merge commit, I also need to cherry-pick other commits, which depend on the change of this merge commit. If I don't cherry-pick the merge commit first, then subsequent cherry-picks will fail.

Anthony Wong
  • 101
  • 3
  • https://stackoverflow.com/a/9229393/2436175 (doesn't look like a good idea what you are trying to do) – Antonio May 10 '18 at 20:48
  • 1
    Unless you stored the conflict resolutions themselves somewhere, no. However, storing the conflicts and their resolutions is precisely what `git rerere` enables and does, so what you might do is turn on `rerere`, train it by redoing the exact same cherry-pick and simply extracting the final result (see the "rerere train" code https://github.com/git/git/blob/master/contrib/rerere-train.sh), and then let Git re-use the recorded resolutions. – torek May 10 '18 at 20:58

1 Answers1

0

I think git rerere is the correct way to do this, but a quick and dirty way to do it might be to do the merge again and restore the conflicting files from the original merge commit.

So, if you've got:

master A - B - E - F
            \       \
feature      C - D - M1

And what you're trying to do is add a new commit G in feature, then re-merge from master, you can do git reset --hard D and commit or cherry-pick G so you've got:

master A - B - E - F
            \
(detached)   C - D - M1
                  \
feature            G

Now if you re-merge master into feature, you'll get conflicts, but can do:

git checkout M1 -- <conflicting files...>

Which will resolve the conflicts with the changes from the original M1 merge commit, then git commit to create the final tree:

master A - B - E - F --
            \           \
feature      C - D - G - M2
Tom
  • 36,698
  • 31
  • 90
  • 98