Skip to end of metadata
Go to start of metadata

Sometimes merging with git does bad things.  We've seen this happen in two cases.  What we've seen are the following behaviors:

  • Files that were removed are magically re-added on merge
  • Files that were only changed on the destination branch still have "conflicts"
  • Conflicts that would otherwise be self-resolving are hard conflicts with no content from the contributing branch

How to diagnose if you're in this situation:

  • If you've tried a merge, but it just looks messed up and too complicated.  Bring up Stash/Bitbucket and do the following:
  • Press "Create Pull Request" and enter the source and destination branch.  Click "Continue".  Do not click "Create".  Put that on one screen (or one side of your only screen).
  • Bring up another Stash, do the same thing, but click "Create" this time and put that side-by-side with the other.
  • If you notice a lot of differences between the two, there may be something amiss.

How to perform the merge anyway:

  • We found that we want to get that PR "Preview" merge, and not the "Create" PR results.  So we went around merge.
  • Find the latest SHA (commit) of your donor branch
  • Find the first SHA (commit) of your donor branch (this is typically the first commit or the commit of your last merge from that branch)
  • Set your branch to your donor branch.
  • Run "git diff <first-SHA> <latest-SHA> > ../diff.patch"
  • This is a git patch file containing all of the diffs on the donor branch.
  • Set to the branch to your destination branch and create a branch off of it.
  • Apply the git diff by running "git apply --ignore-space-change --ignore-whitespace -3 ..\diff.patch"
  • This will ignore spaces and whitespace and will perform a 3-way merge of the diffs, leaving your (likely) with conflicted files.
  • Now do your normal method of conflict resolution.
  • When committing, be very clear about what you've done:
    • List all the commits between <first-SHA> and <latest-SHA>
    • List all files that were conflicted that you manually merged, just in case.
  • Push your branch and create a PR against the destination branch.

 

For an example of a bad git merge that didn't make it into master, see:

https://review.coprhd.org/projects/CH/repos/coprhd-controller/pull-requests/2883/overview

And the example of the resolution of the issue was this PR:

https://review.coprhd.org/projects/CH/repos/coprhd-controller/pull-requests/2889/overview

 

  • No labels