


(Heck, even a merge without conflicts can break working code.) Tip Four In all cases, you need to do a bit of testing to make sure your changes didn't break anything. If it's a buildable project, then build it before you commit, etc. Verify your changes with automated tools. (So it doesn't include commits that already exist in both branches before merging.) This helps you ignore diff hunks that clearly are not a factor in your current conflict. This shows all of the commits that touched that file in between the common ancestor and the two heads you are merging. Somebody already mentioned this, but understanding the intention behind each diff hunk is generally very helpful for understanding where a conflict came from and how to handle it. This is not the same as using a merge tool, since a merge tool will include all of the non-conflicting diff hunks too. Then I can run the following commands to see the two diff hunks that caused the conflict: diff common mine If the conflict is longer, then I will cut and paste each of the three sections into three separate files, such as "mine", "common" and "theirs". If you're confused, it's probably best to just call that person into your room so they can see what you're looking at.) (Knowing how to fix a conflict is very different you need to be aware of what other people are working on. If the conflict is only a few lines, this generally makes the conflict very obvious. This is useful because you can compare it to the top and bottom versions to get a better sense of what was changed on each branch, which gives you a better idea for what the purpose of each change was. The middle section is what the common ancestor looked like. This produces conflict markers like this: > The best thing I have found is to use the "diff3" merge conflict style: I'm usually more successful looking at the conflict markers in a text editor and using git log as a supplement. I find merge tools rarely help me understand the conflict or the resolution. git checkout -ours filename.cĪnd then we try a final time git pull origin master Oh my, oh my, upstream changed some things, but just to use my changes.no.their changes. So you decide to take a look at the changes: git mergetool Git commit -m "made some wild and crazy changes"ĬONFLICT (content): Merge conflict in filename.cĪutomatic merge failed fix conflicts and then commit the result.

So you get up-to-date and try again, but have a conflict: git add filename.c You're going to pull some changes, but oops, you're not up to date: git fetch originĮrror: Entry 'filename.c' not uptodate. Here's a probable use case, from the top: If you want to get changes from LOCAL :diffg LO If you want to get changes from BASE :diffg BA If you want to get changes from REMOTE :diffg RE More information about vimdiff navigation is You can directly reach the MERGED view using ctrl+ w followed by j. You can navigate among these views using ctrl+ w. MERGED: the merge result this is what gets saved in the merge commit and used in the future.REMOTE: the file you are merging into your branch.BASE: the common ancestor, how this file looked before both changes.LOCAL: this is the file from the current branch.Run the following command in your terminal git mergetool This will set vimdiff as the default merge tool. Run the following commands in your terminal git config merge.tool vimdiff Kdiff3, tkdiff, xxdiff, tortoisemerge, gvimdiff, diffuse,Įcmerge, p4merge, araxis, vimdiff, emerge.īelow is a sample procedure using vimdiff to resolve merge conflicts, based on One of the following tools to use it instead: meld, opendiff, Running git mergetool for me resulted in vimdiff being used. It is much better than doing the whole thing by hand certainly.ĭoesn't necessarily open a GUI unless you install one. Sometimes it requires a bit of hand editing afterwards, but usually it's enough by itself. It opens a GUI that steps you through each conflict, and you get to choose how to merge.
