Skip to main content

Git for Authors

Chapter 5 Merge Conflicts

How-to for resolving a merge conflict
git mergetool, meld
We present similar three-step recipes for a resolving conflicts that occur either during a rebase, or during a (non-fast-forward) merge.
List 5.0.1. Resolving a Rebase Conflict
  1. In the output announcing the conflict, git will list exactly which files have merge conflicts. Open these files in your editor and search for ========. Above and below a this line of equal signs you will see the text that git cannot resolve itself delimited with hints on where it comes from. Edit freely to make the text look the way you want it, and remove the markers: <<<<<<<, ========, >>>>>>>.
  2. git add <file1> <file2> <file3>
    You need to stage your changes in the index in preparation for a commit, as usual. At this point, git status will include
    (all conflicts fixed: run "git rebase --continue")
    
    so go ahead. Notice that you are not given an opportunity to change the commit message, and maybe your edits make this desirable. This can be done later, see interactive rebasing in ChapterĀ 6.
  3. git rebase --continue
    You have modified the commit that did not rewind smoothly, and so this command tells git to continue replaying commits from the branch, including the one it is in the midst of replaying. The remaining commits may apply smoothly, or they may present new conflicts. So you may go through this recipe several times.
List 5.0.2. Resolving a Merge Conflict
  1. In the output announcing a merge conflict, git will list exactly which files have merge conflicts. Open these files in your editor and search for ========. Above and below a this line of equal signs you will see the text that git cannot resolve itself delimited with hints on where it comes from. Edit freely to make the text look the way you want it, and remove the markers: <<<<<<<, ========, >>>>>>>.
  2. git add <file1> <file2> <file3>
    You need to stage your changes in the index in preparation for a commit, as usual.
  3. git commit -m "Fixing merge conflict by..."
    You now create one new commit, a merge commit. Remember, in a merge no commits change in any way. But here you do create an additional new commit that is slightly different in nature. It holds the changes you made to resolve the conflicts, but unlike other commits, it has two parents, not one. These are the tips of the two branches that are being merged. This what makes a regular merge different from a fast-forward merge. In show-branch it will be shown distinctively as a dash, not an asterisk or exclamation point.