Skip to content

Instantly share code, notes, and snippets.

@thehig
Forked from Skymetal/complexMerge.md
Created October 9, 2017 13:02
Show Gist options
  • Save thehig/3d08f3ad1f5e76c4ffa1875702788b2e to your computer and use it in GitHub Desktop.
Save thehig/3d08f3ad1f5e76c4ffa1875702788b2e to your computer and use it in GitHub Desktop.
git: Complex merge

Performing a very complex merge

The problem

  • We have two servers, one named staging, one named production.
  • We have made changes on the staging branch to:
    • Use an alternate authentication source
    • Display more complex errors
    • Communicate with the staging server
  • We have branched from staging to implement a new feature (feature-easypost)
  • We want to merge the relevant changes from feature-easypost into feature/twotap
  • We want to avoid bringing the staging changes onto our main development branch.
    • We often merge onto staging to test our recent changes on the staging server.

We couldn't merge the branches because there were commits we did not want from way back, but that is technically the last ancestor. What we needed was a subset of changes made from the branch point (staging -> feature-easypost) to the branch head (feature-easypost) to merge onto feature/twotap, which has never had staging merged into it.

The solution

Git can now cherry pick a list of commits git cherry-pick A..B

Identifying the right points

  • Using TortiseGit we got the commit SHA of

    • Last commit on staging (d959fd2e)
    • Last commit on feature-easypost (054fed1f)
  • Using git we listed the commits between these points

    • git log --pretty=oneline d959fd2e..054fed1f
    • This listed 24 commits, which seemed right
  • We then cherry-picked those 24 commits

    • git cherry-pick d959fd2e..054fed1f
    • Note: Might have missed one

Note that cherry-pick A..B will not get commit A (you would need A~1..B for that) (source)[http://stackoverflow.com/questions/1994463/how-to-cherry-pick-a-range-of-commits-and-merge-into-another-branch]

  • We manually checked the files that we knew would be changed by staging and they seemed to be correct
  • To avoid any potential issues we create a new branch and push the changes on that branch for further examination
    • git checkout -b merge/twotap-easypost
    • git push --set-upstream origin merge/twotap-easypost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment