741

What's the best tool for viewing and editing a merge in Git? I'd like to get a 3-way merge view, with "mine", "theirs" and "ancestor" in separate panels, and a fourth "output" panel.

Also, instructions for invoking said tool would be great. (I still haven't figure out how to start kdiff3 in such a way that it doesn't give me an error.)

My OS is Ubuntu.

9
  • What OS do you want instructions for? Commented Sep 26, 2008 at 0:45
  • 5
    Using kdiff3 with "git mergetool" should work fine. I have had no problems with that. Commented Sep 30, 2010 at 14:05
  • 1
    To just diff, do kdiff3 file1 file2a or kdiff3 file1 file2a file2b (this assumes that file1 is a common ancestor to file2a and file2b), and to do a three way merge with those files and outputting the merged file to file3 do kdiff3 -b file1 file2a file2b -o file3. Commented Mar 2, 2011 at 18:45
  • 1
    If this question was open, I would make an answer suggesting xxdiff. 4 file displays and word level diff on each line Commented Jul 2, 2016 at 12:05
  • 13
    There is softwarerecs.stackexchange.com Commented Feb 13, 2017 at 16:34

18 Answers 18

436

Meld is a free, open-source, and cross-platform (UNIX/Linux, OSX, Windows) diff/merge tool.

Here's how to install it on:

Sign up to request clarification or add additional context in comments.

20 Comments

who cares about the OS the original author is using?, the question is general enough to be of interest to everyone who looks for it. And 3-way diff is when you actually see 4 panes with test; merge-base/local/remote/result
meld is tedious with complex diffs, being able to select options like chose b for all unresolved conflicts is much better than having to manually click on the correct arrow for every hunk in meld. Also, being able to merge into a specific output file rather than edit the input files in place is invaluable for backing out of failed nerges.
@naxa Meld now has a Windows installer: code.google.com/p/meld-installer
kdiff3 let you see 4 views, meld only allows 3 views. Meld isn't a real merge tool, it's a diff tool since it doesn't shows the base version view.
Meld is horrible, especially for merges. It has no option to "auto-transfer non-conflicting changes", making every merge horribly painful.
|
100

You can configure your own merge tool to be used with "git mergetool".

Example:

 git config --global merge.tool p4merge git config --global mergetool.p4merge.cmd p4merge '$BASE $LOCAL $REMOTE $MERGED' git config --global mergetool.p4merge.trustExitCode false 

And while you are at it, you can also set it up as your difftool for "git difftool":

 git config --global diff.tool p4merge git config --global difftool.p4merge.cmd p4merge '$LOCAL $REMOTE' 

Note that in Unix/Linux you don't want the $BASE to get parsed as a variable by your shell - it should actually appear in your ~/.gitconfig file for this to work.

2 Comments

Note that since p4merge is (now) one of the officially supported git mergetools, it shouldn't be necessary to muck with the tool..cmd variable anymore.
Make sure you're using correct quotation: stackoverflow.com/a/1217994/3543437
80

Beyond Compare 3, my favorite, has a merge functionality in the Pro edition. The good thing with its merge is that it let you see all 4 views: base, left, right, and merged result. It's somewhat less visual than P4V but way more than WinDiff. It integrates with many source control and works on Windows/Linux. It has many features like advanced rules, editions, manual alignment...

The Perforce Visual Client (P4V) is a free tool that provides one of the most explicit interface for merging (see some screenshots). Works on all major platforms. My main disappointement with that tool is its kind of "read-only" interface. You cannot edit manually the files and you cannot manually align.

PS: P4Merge is included in P4V. Perforce tries to make it a bit hard to get their tool without their client.

SourceGear Diff/Merge may be my second free tool choice. Check that merge screens-shot and you'll see it's has the 3 views at least.


Meld is a newer free tool that I'd prefer to SourceGear Diff/Merge: Now it's also working on most platforms (Windows/Linux/Mac) with the distinct advantage of natively supporting some source control like Git. So you can have some history diff on all files much simpler. The merge view (see screenshot) has only 3 panes, just like SourceGear Diff/Merge. This makes merging somewhat harder in complex cases.

PS: If one tool one day supports 5 views merging, this would really be awesome, because if you cherry-pick commits in Git you really have not one base but two. Two base, two changes, and one resulting merge.

7 Comments

Perforce Merge is great. It has a 4 pane merge tool, which really helps: Yours, Theirs, Common Base, New
P4 is also used by Google.
You can custom install only P4Merge without the rest of perforce.
The latest version of p4merge does not have the "read-only" interface. You can edit the merged file in the lower pane.
This is a really great answer and discussion. Thank you for sharing!
|
69

I hear good things about kdiff3.

8 Comments

+1: kdiff3 is far superior to meld and is also natively supported by git.
kdiff3 has far more features but meld has better UI. In my opinion, meld is better for easy merges where the features provided by meld are enough. Remember to try diffuse, too.
kdiff3 let you see 4 views, meld only allows 3 views. Meld isn't a real merge tool, it's a diff tool since it doesn't shows the base version view.
kdiff3 is OK, but it often fails with 'Data loss' errors, and in this cases alternative is needed
kdiff3 is free, but this is just crippled and ugly version of Beyond Compare.
|
60

IntelliJ IDEA has a sophisticated merge conflict resolution tool with the Resolve magic wand, which greatly simplifies merging:

Source: https://blog.jetbrains.com/dotnet/2017/03/13/rider-eap-update-version-control-database-editor-improvements/

4 Comments

Idea's merge tool is just brilliant. it is even available in Idea's community edition which means you can use it for free as advanced merge tool - this is what I'm doing (for most cases I use VSCode where I'm working and I use Idea for tough merge cases). VSCode does pretty good job as well, and sometimes even better then Idea. but for tough cases their 3-panels-layout is the best tool I've ever seen
I hate how the scroll bar 'file summery' are NOT together! The main reason I like diffuse!
didnt work for me
If you fancy invoking the tool from command line, in graphical login (about you Linux fans), jetbrains.com/help/idea/command-line-merge-tool.html idea.sh merge <path1> <path2> [<base>] <output> .. There are some quirks with it, so follow this blog post
46

My favorite visual merge tool is SourceGear DiffMerge

  • It is free.
  • Cross-platform (Windows, OS X, and Linux).
  • Clean visual UI
  • All diff features you'd expect (Diff, Merge, Folder Diff).
  • Command line interface.
  • Usable keyboard shortcuts.

User interface

5 Comments

how do you configure it to work with git?
Thank you for introducing it to me!! :D This tool is clean and took less time to install and work with than meld. I spend half hour trying to install meld. But this one I did in 5 min!!
Note: diffmerge doesn't appear to have a 3-way merge feature. I'm abandoning it after trying it for a couple weeks for that reason
It's a nice tool and also can compare folders. The problem is its kinda slow (MacBookPro 15 2014, MacOS Catalina)
40

vimdiff

Once you have have learned vim (and IMHO you should), vimdiff is just one more beautiful little orthogonal concept to learn. To get online help in vim:

:help vimdiff 

This question covers how to use it: How do I use vimdiff to resolve a conflict?

enter image description here

If you're stuck in the dark ages of mouse usage, and the files you're merging aren't very large, I recommend meld.

6 Comments

<3 vimdiff, I can't figure out how to convince svn to let me use it as a 'merge' tool.
gvimdiff also works well for this purpose.
Using the Fugitive plugin makes it even easier! vimcasts.org/episodes/…
If only there was a way to clearly see the diff between local / base and base / remote.
mcdiff is another handy CLI merge tool, from mc package (Midnight Commander).
|
30

You can try P4Merge.

Visualize the differences between file versions with P4Merge. Resolve conflicts that result from parallel or concurrent development via color coding.

The features includes:

  • Highlight and edit text file differences
  • Choose to include or ignore line endings or white spaces
  • Recognize line-ending conventions for Windows (CRLF), Mac (CR), and Unix (LF)
  • Use command-line parameters and launch from non-Perforce applications
  • Display line numbers when comparing and merging files
  • Exclude files that are modified, unique, or unchanged
  • Filter files by name or extension
  • Organize modified assets in familiar file/folder hierarchy
  • Compare JPEG, GIF, TIFF, BMP, and other file formats
  • Extend using the Qt API
  • Overlay images or display side-by-side
  • Highlight differences on overlaid images

4 Comments

best one i've seen so far. easily resolve conflicts by picking the change from the list of the three-way view
Started using it today and it's pretty intuitive.
17

Diffuse is my favourite but of course I am biased. :-) It is very easy to use:

$ diffuse "mine" "output" "theirs" 

Diffuse is a small and simple text merge tool written in Python. With Diffuse, you can easily merge, edit, and review changes to your code. Diffuse is free software.

4 Comments

I really like diffuse, and I'm not biased.
@Derrick Moser: diffuse looks very nice. I just tried it now and it did better diffing than kdiff3. But, I'm trying to use it with git mergetool and it opens 4 files next to each other (local, merge-result, remote, base), and my screen isn't quite wide enough for that. I had to do a lot of horizontal scroll. kdiff3 only shows 3 next to each other and the result on the lower half of the window.
diffuse has some additional merge options in comparison to meld (allows to join both versions rather than picking one of them).
diffuse works out of the box on windows, for comparing 2 folders, with CVS repo, with Git repo, merging git merge conflicts. The diffuse diff files open in tabs in a single window. I switched to diffuse (after having used emacs' ediff (too many features, useful in 90s) > vimdiff (complicated plugins keystrokes) > p4merge > araxis (proprietry) > meld (too slow), tkdiff (only cvs) > kdiff3 (good, good regex ignore features) > winmerge (good) > diffuse (fast, portable, works as expected) ) the first time I tried diffuse.
15

Araxis Merge http://www.araxis.com/merge I'm using it on Mac OS X but I've used it on windows... it's not free... but it has some nice features... nicer on windows though.

Comments

12

If you are just looking for a diff tool beyond compare is pretty nice: http://www.scootersoftware.com/moreinfo.php

Comments

10

If you use visual studio, Team Explorer built-in tool is a very nice tool to resolve git merge conflicts.

2 Comments

I found there is an issue with the visual studio diff tool. It doesn't support word wrap at the moment. Also, there is no way to jump to the next difference unlike other tools which support these basic features.
I know this is a very old question, but in 2022, after trying a bunch of other tools, using the default merge resolution tool in VS Code actually ended up being the easiest for me to understand and use. This answer led me to that, thank you.
8

You can change the tool used by git mergetool by passing git mergetool -t=<tool> or --tool=<tool>. To change the default (from vimdiff) use git config merge.tool <tool>.

Comments

8

So for the git merge, you can try:

  • DiffMerge to visually compare and merge files on Windows, OS X and Linux.

    DiffMerge

  • Meld, is a visual diff and merge tool.

    Meld is a visual diff and merge tool

  • KDiff3, a diff and merge program), which compares or merges 2 or 3 text input files/dirs.
  • opendiff (part of Xcode Tools on macOS), a command line utility which launches the FileMerge application from Terminal to graphically compare files or directories, including merging.

1 Comment

git config --global merge.tool opendiff worked best for me
7

I use different tools for merge and compare:

git config --global diff.tool diffuse git config --global merge.tool kdiff3 

First could be called by:

git difftool [BRANCH] -- [FILE or DIR] 

Second is called when you use git mergetool.

Comments

6

I've tried a lot of the tools mentioned here and none of them have quite been what I'm looking for.

Personally, I've found Atom to be a great tool for visualizing differences and conflict resolution/merging.

As for merging, there aren't three views but it's all combined into one with colored highlighting for each version. You can edit the code directly or there are buttons to use whichever version of that snippet you want.

I don't even use it as an editor or IDE anymore, just for working with git. Clean UI and very straight-forward, plus it's highly customizable.

  • You can start it from the command line and pass in a single file you want to open to, or add your project folder (git repo).

    • I would also recommend project-manager as a very convenient way to navigate between projects without filling up your tree view.
  • The only problem I've had is refreshing -- when working with large repositories atom can be slow to update changes you make outside of it. I just always close it when I'm finished, and then reopen when I want to view my changes/commit again. You can also reload the window with ctrl+shift+f5, which only takes a second.

And it's free of course.

Comments

3

You can install ECMerge diff/merge tool on your Linux, Mac or Windows. It is pre-configured in Git, so just using git mergetool will do the job.

Comments

0

gitx http://gitx.frim.nl/

Some bugs when working with large commit sets but great for browsing through changes and picking different changes to stage and then commit.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.