712

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.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
andy
  • 18,005
  • 9
  • 30
  • 27
  • What OS do you want instructions for? – Luke Sep 26 '08 at 00:45
  • 4
    Using kdiff3 with "git mergetool" should work fine. I have had no problems with that. – Zitrax Sep 30 '10 at 14:05
  • 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`. – Mark Booth Mar 02 '11 at 18:45
  • 1
    If this question was open, I would make an answer suggesting [xxdiff](http://furius.ca/xxdiff/). 4 file displays and word level diff on each line – BeniBela Jul 02 '16 at 12:05
  • 13
    There is https://softwarerecs.stackexchange.com/ – Philipp Wendler Feb 13 '17 at 16:34
  • It depends. kdiff3 and p4merge are both free and work easily with git. kdiff3 has the --auto feature which is useful for scripting. I have found that p4merge is significantly better at automatically resolving conflicts. – user1976 Apr 06 '17 at 17:23
  • For me, the best tool would be one which has high quality courses (not random junk Udemy courses). Once one learns the fundamentals of tools, I guess it would be easy to learn other tools. I am yet to find which tool meets my criteria. – MasterJoe Mar 05 '19 at 20:57
  • Related: https://stackoverflow.com/questions/14821358/git-mergetool-with-meld-on-windows/48979939 – Gabriel Staples Feb 12 '21 at 19:23
  • After having tried almost all of them on Windows I can say WinMerge is easily the one that for me worked the best taking into account speed and provided features – Redoman Mar 29 '23 at 23:09

18 Answers18

417

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

Here's how to install it on:

Csa77
  • 649
  • 13
  • 19
user20805
  • 1,347
  • 1
  • 11
  • 10
  • 61
    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 – Evgeny Jan 23 '11 at 13:16
  • 24
    `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. – Mark Booth Mar 02 '11 at 18:51
  • Meld doesn't work correctly as merge tool with git as it shows merge markers. – slikts Dec 22 '11 at 13:38
  • @jnnnnn i can confirm that meld definitely do work on windows. it just lacks the installer. – n611x007 Aug 09 '12 at 15:45
  • 1
    @jooks http://meldmerge.org/. Meld might not be the best one, but it works great for me :) – codefreak Feb 14 '13 at 08:03
  • 3
    @naxa Meld now has a Windows installer: https://code.google.com/p/meld-installer/ – Roman Mar 18 '13 at 11:01
  • For Ubuntu it's exactly what I needed https://gist.github.com/fedir/7661179 – Fedir RYKHTIK Nov 26 '13 at 16:16
  • 2
    There is now a meld windows installer (as of at least 1.8). Go to their site and they have a link to Sourceforge. Was Google Code then it move, who knows what will happen. So, check their site for the link. – QueueHammer Apr 30 '14 at 17:14
  • Mac link is down. Here's an other one: http://www.alexkras.com/how-to-run-meld-on-mac-os-x-yosemite-without-homebrew-macports-or-think/ – rousseauo Sep 29 '15 at 18:02
  • 11
    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. – Akira Yamamoto May 05 '16 at 18:44
  • Note: you need to install python 3.3 or higher for latest `meld`. – vineet Jan 10 '17 at 05:36
  • 2
    Meld has some problems. It makes it really annoying to do "Mine then theirs" changes. And it's kind of hard to read sometimes. – Morgan LaVigne May 08 '17 at 15:41
  • 10
    Meld is horrible, especially for merges. It has no option to "auto-transfer non-conflicting changes", making every merge horribly painful. – Cerin May 25 '17 at 22:40
  • 1
    No https on site. Will not proceed. – Ryan May 25 '19 at 21:34
  • @Ryan: nowadays the site's reachable via HTTPS and there's a redirect to it from plain HTTP. – paprika Jan 01 '20 at 22:36
  • For Windows and Linux install instructions for `meld`, so you can run `git difftool` to see file changes using `meld`, here's my answer: https://stackoverflow.com/a/48979939/4561887. – Gabriel Staples Feb 12 '21 at 19:24
  • 1
    @Cerin That's not true, in the menu there's "Changes" -> "Merge All" which merges non-conflicting hunks. – pcworld May 12 '21 at 17:17
  • From your link: "Meld is not yet supported on OS X." – johntrepreneur Jan 18 '23 at 21:14
  • After having tried almost all of them on Windows I can say WinMerge is easily the one that for me worked the best taking into account speed and provided features. – Redoman Mar 29 '23 at 23:07
101

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.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Evgeny
  • 6,533
  • 5
  • 58
  • 64
  • 11
    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. – Matt Ball May 03 '11 at 15:52
  • 2
    Make sure you're using correct quotation: http://stackoverflow.com/a/1217994/3543437 – kayleeFrye_onDeck Mar 21 '16 at 23:58
76

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.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Wernight
  • 36,122
  • 25
  • 118
  • 131
  • 9
    Perforce Merge is great. It has a 4 pane merge tool, which really helps: Yours, Theirs, Common Base, New – Gal May 24 '11 at 00:17
  • 5
    P4 is also [used by Google](http://www.quora.com/What-version-control-system-does-Google-use-and-why). – Wernight Aug 02 '11 at 08:03
  • 6
    You can custom install only P4Merge without the rest of perforce. – Dirk Bester May 10 '12 at 22:19
  • 7
    The latest version of p4merge does not have the "read-only" interface. You can edit the merged file in the lower pane. – Ian Ni-Lewis Nov 21 '12 at 01:13
  • 1
    This is a really great answer and discussion. Thank you for sharing! – Mark Good Mar 17 '15 at 22:04
  • 1
    I've used both P4Merge and Beyond Compare (BC). The company I used to work for had a site license for BC Pro. Everyone got to choose whichever one they wanted, or could download their own tool. **Everyone used BC**. Note that the "Standard Edition" is $30, while the "Pro" version is $60 as I write this. No affiliation, I just happen to like their software. That and Visual Assist. Mmmm... – Mark Storer Jun 03 '20 at 18:46
60

I hear good things about kdiff3.

kryger
  • 12,906
  • 8
  • 44
  • 65
  • 6
    +1: kdiff3 is far superior to meld and is also natively supported by git. – Mark Booth Mar 02 '11 at 18:37
  • 5
    `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. – Mikko Rantalainen Aug 07 '13 at 10:03
  • 1
    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. – Akira Yamamoto May 05 '16 at 18:41
  • 1
    kdiff3 is OK, but it often fails with 'Data loss' errors, and in this cases alternative is needed – user377178 Oct 02 '20 at 09:36
  • I find that kdiff3 is terribly superior, solving most of the merge issue himself thanks a great matching with the common ancestor. – daminetreg Sep 03 '21 at 09:51
  • 1
    kdiff3 is free, but this is just crippled and ugly version of Beyond Compare. – Marek R Sep 20 '21 at 09:58
53

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/

niutech
  • 28,923
  • 15
  • 96
  • 106
  • 10
    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 – godblessstrawberry Oct 10 '19 at 08:10
  • I hate how the scroll bar 'file summery' are NOT together! The main reason I like diffuse! – anthony Jan 17 '20 at 06:44
  • didnt work for me – Gonzalo Garcia Jul 23 '20 at 19:05
  • If you fancy invoking the tool from command line, in graphical login (about you Linux fans), https://www.jetbrains.com/help/idea/command-line-merge-tool.html `idea.sh merge [] ` .. There are some quirks with it, so follow [this blog post](https://coderwall.com/p/gc_hqw/use-intellij-or-webstorm-as-your-git-diff-tool-even-on-windows) – ϹοδεMεδιϲ Mar 06 '22 at 19:46
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

Nafeez Abrar
  • 1,045
  • 10
  • 27
Luke
  • 18,585
  • 24
  • 87
  • 110
  • 4
    how do you configure it to work with git? – Ryan Lundy Mar 29 '11 at 21:59
  • 2
    @Kyralessa See http://stackoverflow.com/questions/255202/how-do-i-view-git-diff-output-with-visual-diff-program – Luke Mar 30 '11 at 23:47
  • 2
    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!! – om39a Mar 10 '14 at 16:03
  • 4
    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 – StormeHawke Oct 10 '14 at 15:30
  • It's a nice tool and also can compare folders. The problem is its kinda slow (MacBookPro 15 2014, MacOS Catalina) – emKaroly Jan 05 '20 at 14:54
37

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.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Andrew Wagner
  • 22,677
  • 21
  • 86
  • 100
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
kenorb
  • 155,785
  • 88
  • 678
  • 743
Ron
  • 1,932
  • 20
  • 17
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.

kenorb
  • 155,785
  • 88
  • 678
  • 743
  • 2
    I really like diffuse, and I'm not biased. – jturcotte Sep 11 '09 at 13:16
  • 2
    @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. – yairchu Dec 09 '10 at 09:54
  • diffuse has some additional merge options in comparison to meld (allows to join both versions rather than picking one of them). – Audrius Meškauskas Apr 26 '13 at 15:24
  • 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. – mosh Feb 13 '18 at 02:41
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.

Clintm
  • 4,505
  • 3
  • 41
  • 54
9

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

Nathan Feger
  • 19,122
  • 11
  • 62
  • 71
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>.

user35149
  • 311
  • 1
  • 2
  • 7
7

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.
kenorb
  • 155,785
  • 88
  • 678
  • 743
6

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

CuriousGuy
  • 3,818
  • 4
  • 24
  • 28
  • 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. – Harsha J K Jul 15 '22 at 04:27
  • 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. – Carlos Sanchez Dec 24 '22 at 23:45
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.

Styx
  • 9,863
  • 8
  • 43
  • 53
Sean McCallum
  • 158
  • 2
  • 10
6

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.

user240515
  • 3,056
  • 1
  • 27
  • 34
ephemerr
  • 1,833
  • 19
  • 22
2

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.

akjoshi
  • 15,374
  • 13
  • 103
  • 121
Armel
  • 21
  • 1
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.