git - set KDiff3 as default mergetool
Asked Answered
M

2

5

After installing KDiff3 for managing conflicts in git, still the default one is opening for me:

enter image description here

Here is the configuration that mentioned in this answer:

git config --global --add merge.tool kdiff3
git config --global --add mergetool.kdiff3.path "C:/Program Files/KDiff3/kdiff3.exe"
git config --global --add mergetool.kdiff3.trustExitCode false

git config --global --add diff.guitool kdiff3
git config --global --add difftool.kdiff3.path "C:/Program Files/KDiff3/kdiff3.exe"
git config --global --add difftool.kdiff3.trustExitCode false

NOTE: I can be able to run KDiff3 individually with simple files, but I can't run it in my git project. Any idea?

Edit: Here is my .gitconfig :

[user]
    email = [email protected]
    name = vahid najafi
[diff]
    tool = kdiff3
    guitool = kdiff3
[merge]
    tool = diffmerge
    tool = kdiff3
    tool = kdiff3
[mergetool "diffmerge"]
    trustExitCode = true
[mergetool "kdiff3"]
    path = C:/Program Files/KDiff3/kdiff3.exe
    trustExitCode = false
[difftool "kdiff3"]
    path = C:/Program Files/KDiff3/kdiff3.exe
    trustExitCode = false
Momentarily answered 5/3, 2017 at 17:43 Comment(1)
Does this answer your question? How can I configure KDiff3 as a merge tool and diff tool for git?Gobbledegook
M
4

Finally I made another solution! I used meld instead of kdiff3. First download meld from here. Then change config for meld in c:/Users/yourName/.gitconfig :

[user]
    email = [email protected]
    name = vahid najafi
[diff]
    tool = meld
[difftool "meld"]
    path = C:/Program Files (x86)/Meld/meld/meld.exe
[difftool]
    prompt = false
[merge]
    tool = meld
[mergetool "meld"]
    path = C:/Program Files (x86)/Meld/meld/meld.exe
[mergetool]
    keepBackup = false

NOTE: Try to use git cmd instead of windows cmd. When you have conflict, just run : git mergetool. For more detail and example, see here.

Momentarily answered 6/3, 2017 at 12:20 Comment(1)
Expect the answer for KDiff3 to be very similar to your answer here. ~ * ~ An advantage of using Git Bash instead of Git cmd is that the commands will be the same (often identical) as those on Linux and macOS.Gobbledegook
A
3

I do not know kdiff3, but you might need to add the files you want to compare to your tool call as parameters (see command line options for KDiff3 call here). In your global config (accessible via git config --global -e), the respective lines should look something like this:

[merge]
    tool = kdiff3
[mergetool "kdiff3"]
    trustExitCode = false
    cmd = 'C:/Program Files/KDiff3/kdiff3.exe' "$LOCAL" "$BASE" "$REMOTE" "$MERGED"

Since I did not try this with KDiff3, you might have to switch the order of "$LOCAL" "$BASE" "$REMOTE"and "$MERGED" variables, but this post sould provide enough additional more information on this. Although it's about the Meld tool, I'm pretty sure the handling is analogical, and there are some pretty good and informative answers.

EDIT: Assuming you use windows: You can just locate it in Windows explorer, usually in c:\user\yourusername\.gitconfig, and open it with any editor. In Linux, see this post. Then, replace all the merge, mergetooland difftool sections with the following:

[merge]
    tool = kdiff3
[mergetool "kdiff3"]
    cmd = "C:/Program Files/KDiff3/kdiff3.exe" "$LOCAL" "$BASE" "$REMOTE" "$MERGED"
    trustExitCode = false
[difftool "kdiff3"]
    cmd = "C:/Program Files/KDiff3/kdiff3.exe" "$LOCAL" "$BASE" "$REMOTE" "$MERGED"
    trustExitCode = false

If ot does not work, it is possible that you have to change the order of "$LOCAL" "$BASE" "$REMOTE"and "$MERGED" variables or remove one of them. You can find sufficient information about this in the links provided above.

Allynallys answered 6/3, 2017 at 6:17 Comment(9)
Thanks. I run git config --global -e , but this part doesn't exist: "$LOCAL" "$BASE" "$REMOTE" "$MERGED"Momentarily
Yes, I expected as much. You should add it to make sure KDiff3 is called with the right files.Allynallys
How should I add? As I'm pretty new to this.Momentarily
You can either run git config --global difftool.kdiff3.cmd"C:/Program Files/KDiff3/kdiff3.exe" "$LOCAL" "$BASE" "$REMOTE" "$MERGED" from command line, setting the value in your config file, or edit the whole config file directly. git config --global -e opens the config file in the default editor (using git for windows, this would be vim). I would edit the whole file directly, since you can make sure there are no leftovers from all the command line editing.Allynallys
I run the command you mentioned, but nothing is changed. I added my .gitconfig file to the question. How can I add it manually?Momentarily
Now I get this error: /mingw64/libexec/git-core/git-mergetool--lib: line 124: C:/Program: No such file or directory fatal: external diff died, stopping at index.php .Momentarily
I even installed meld. It works fine when running git difftool origin/master , but when running git mergetool again it lead me to default mergetool in cmd.Momentarily
I was working on windows cmd. So migrated to git cmd. It solved the problem with meld. Anyway, thanks for paying attention.Momentarily
In my case, I had to add the -o arg before the "$MERGED", so my config line has to be: cmd = "C:/Program Files/KDiff3/kdiff3.exe" "$LOCAL" "$BASE" "$REMOTE" -o "$MERGED"Pico

© 2022 - 2024 — McMap. All rights reserved.