Skip to content

Instantly share code, notes, and snippets.

@domcleal domcleal/README.md
Last active May 8, 2017

Embed
What would you like to do?
Resolve simple git merge/rebase conflicts

Setup

  1. git clone https://gist.github.com/abef31ca104ecffa2d99fb904aadcf59.git git-merging
  2. cd git-merging

Merging

Merge the change-value branch into master, to bring in the change of value:

  1. git merge origin/change-value will fail with "Automatic merge failed; fix conflicts and then commit the result."
  2. Edit app.pl and keep the top block after the conflict marker, make the change from 7 to 42 and delete the unused block and all conflict markers.
  3. git add app.pl
  4. git commit

Tip: if it goes wrong when editing, run git merge --abort and start again.

The git log will now contain the original master commits, the change from 7 to 42 and then a merge commit that brings both together (with your alteration).

Rebasing

Check out the change-value branch and rebase (update it) on master.

  1. git checkout change-value
  2. git rebase master
  3. Edit app.pl and keep the top block after the conflict marker, make the change from 7 to 42 and delete the unused block and all conflict markers.
  4. git add app.pl
  5. git rebase --continue

Tip: if it goes wrong when editing, run git rebase --abort and start again.

The git log will now contain all of the master commits, then a single change from 7 to 42 in the refactored method from master.

If you now repeated the merge of change-value into master, it would merge cleanly.

#!/usr/bin/env perl -w
sub meaning_of_life {
7;
}
print meaning_of_life . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.