Hello all,
After a lot of branching, merging, pulling, rebasing, etc we'll probably see some conflicts on the source code.
With this post we're gonna learn what's a conflicted merge and how to solve it.
Let's take a look:
Sometimes the merge can't be automatically resolved. When this happens, git leaves the index and working tree in such a state that gives you some information to help resolving the merge.
Files with conflicts are marked specially in the index, so until you resolve the problem and update the index, you can't commit:
$ git commit file.txt: needs merge
If you run "git-status", you will see those files marked as "unmerged", and the files with conflicts will have conflict markers added, like this one:
<<<<<<< HEAD:file.txt Bla Bla ======= Goodbye >>>>>>> 77976da35a11db4580b80ae27e8d65caf5208086:file.txt
All you need to do is edit the files to resolve the conflicts, and then
$ git add file.txt $ git commit
Note that the commit message will already be filled in for you with some information about the merge. Normally you can just use this default message unchanged, but you may add additional commentary of your own if desired.
And that's all you need to know about resolving merge conflicts. That's actually the hard way! Using git-mergetool will probably look easier for some of you.
Let's try:
First of all, let's tell git which merge tool we wanna use. Run:
$ git-config --global merge.tool mytool
Where mytool can be on of: tkdiff, kdiff3, meld, vimdiff, gvimdiff, emerge, xxdiff and opendiff
After that, whenever you get a conflict message you just run:
$ git-mergetool
This will open you preferred merge tool and you'll be able to easily solve that conflict.
On later posts we'll see how to migrate from SVN/CVS to git.
See y'all