38

I tried to use GIT however for me the biggest problem with it is that there is no tool for merge'ing. At least the msysgit does not give me anything. How can I merge in GIT? Are there any great tools for it or do I have to use WinMerge or application like that?

I use Java and Eclipse.

IAdapter
  • 62,595
  • 73
  • 179
  • 242
  • 4
    To clarify: you're asking for a tool that'll help you do three-way merges when you run into conflicts, right? (One of the core things that git does is merge; it just leaves it up to you to resolve conflicts.) – Cascabel Feb 10 '11 at 14:59

5 Answers5

74

I suggest kdiff3. Install it and put something like:

[merge]
        tool = kdiff3
[mergetool "kdiff3"]
        path = c:/Program Files (x86)/KDiff3/kdiff3.exe
[diff]
        tool = kdiff3
        guitool = kdiff3
[difftool "kdiff3"]
        path = c:/Program Files (x86)/KDiff3/kdiff3.exe

in your .gitconfig

To edit the global config (.gitconfig): git config --global --edit

The installation path on your machine may be different from c:/Program Files (x86)/KDiff3/kdiff3.exe. Replace that string above with actual path to your kdiff3 binary. And don't forget you have to use forward slashes, /, and not backward ones (\) like native programs usually do.

Jan Hudec
  • 73,652
  • 13
  • 125
  • 172
  • 28
    To edit the global config (.gitconfig): `git config --global --edit` – Mike Dec 13 '12 at 17:21
  • ^ this should be added to the answer as well. :) – rgin Jul 11 '13 at 06:47
  • 4
    By the way the default installation location might be c:/Program Files/KDiff3/kdiff3.exe – Iman Mohamadi Feb 02 '15 at 10:46
  • 1
    PortableGit1.9.5, Win7-64bit, c:/program files/KDiff3/kdiff3.exe, added values to a global .gitconfig (using /program files/ folder), git config --get prints proper values, git difftool file1.txt file2.txt does nothing, gif difftool --no-index file1.txt file2.txt sysouts an old text diff format, I am inside git resository (git status is fine). Strange. – Whome Apr 08 '15 at 08:44
  • ^skip that. Did not realize $ git difftool does nothing if repo does not have changes. Its not a standalone diffing command. Made home/bin/difftool batch script and can now run both standalone diffing and repo diffing from gitportable console. – Whome Apr 08 '15 at 09:17
  • I recommend adding `prompt = false` under `[difftool]` – Jake88 Nov 21 '16 at 16:01
  • Use `git difftool` to use the tool while taking the diff. – ptntialunrlsd Jun 05 '17 at 11:47
3

For me (windows xp, kdiff3 0.9.96 and git 1.7.5.1), Jan Hudec's answer did not work. Here is my setup:

[diff]
        tool = kdiff3
        guitool = kdiff3

[difftool]
        prompt = false

[difftool "kdiff3"]
        path = /home/username/bin/difftool-kdiff3.sh

and

#!/bin/sh

# Passed the following parameters from git
#  --auto --L1 "somefile (A)" --L2 "somefile (B)" /tmp/4VhUw0_somefile somefile

LOCAL=$6
REMOTE=$7

"C:/Program Files/KDiff3/kdiff3.exe" $(cygpath -w "$LOCAL") "$REMOTE"
hlovdal
  • 26,565
  • 10
  • 94
  • 165
  • 1
    My answer is for the [native Windows Git (MSysGit)](http://git-scm.com/download/win). If you use Cygwin Git with native KDiff3, you need this wrapper using `cygpath`. But I prefer the MSysGit even though I mostly use it from cygwin shell (I've mounted the disks on /c/, /d/ etc. and then msys tools understand paths without need for translation; truly native ones still don't). – Jan Hudec Dec 20 '13 at 17:08
2

Since you mention you use Eclipse, you can use EGit's merge tools, which provides a convenient way to handle conflicts:

enter image description here

enter image description here

Franck Dernoncourt
  • 77,520
  • 72
  • 342
  • 501
2

Kdiff3 is a great merge tool that I like to use in combination with git.

http://www.mainelydesign.com/blog/view/using-kdiff3-as-git-gui-merge-tool-on-windows-xp-windows-7

Neil
  • 7,227
  • 5
  • 42
  • 43
Ezra
  • 1,388
  • 1
  • 13
  • 14
0

You don't actually need another tool specifically for merging, since any decent Git provider should be able to take care of that, even msysgit itself. In your case where a GUI like WinMerge is desirable, there is EGit, which is the Git team provider for Eclipse, although its merge function can be somewhat unstable since the project is still relatively new. There is also TortoiseGit which I use for most git operations on Windows inclusive of merge.

prusswan
  • 6,853
  • 4
  • 40
  • 61