Home > Software design >  Retrieve only manual changes from a merge commit
Retrieve only manual changes from a merge commit

Time:09-20

I have a merge commit, where I manually resolved conflicts and made other necessary adjustments, so the code after the merge commit can be compiled and pass tests. The merge commit is large and both parent branches were reviewed and successfully run tests. So reviewers only want to check the manual adjustments in the merge commit.

Can I retrieve those manual changes and how?

CodePudding user response:

... reviewers ... want to check the manual adjustments in the merge commit.

There isn't an easy way to get these, but there is a way that's not hard (it's a little in-between):

  • Run the merge again (which will get the same conflicts). Do this by checking out, as a detached HEAD, one of the two commits you merged, and then merging the other commit.
  • Commit the result, complete with merge conflicts. Note down the resulting hash ID; you might even wish to make a branch or tag name for it.
  • Distribute this commit you just made and/or a diff from this commit to your own merge commit.

Edit: actual commands, as per request, though this hardly adds anything to the above:

git switch --detach <hash1>
git merge <hash2>
git add .
git commit
git rev-parse HEAD

(Note down the hash ID here, or run git tag or git branch now to create a tag or branch name for it)

You now have a merge commit with the conflicts in it. Diff this merge commit against your own merge commit, whatever its hash ID is:

git diff <hash1> <hash2>

to see how you resolved the conflicted sections. (Note that this diff will not be pretty.)

  • Related