Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: configure patterns for difftool and mergetool

In Mercurial, one can define a pattern for external diff and merge tools (so that they are called only for files matching the pattern specified):

[diff-patterns]
**.ext = difftool
[merge-patterns]
**.ext = mergetool

How to define such patterns in Git?

[mergetool] section in git-config(1) does not mention any pattern, mask or anyting similar.

EDIT:

Here is a relevant part of my .git/config:

[diff]
    tool = difftool
[difftool "difftool"]
    cmd = difftool.git.sh "$LOCAL" "$REMOTE" "$BASE"

[merge]
    tool = mergetool
[mergetool "mergetool"]
    cmd = mergetool.git.sh "$LOCAL" "$REMOTE" "$BASE" "$MERGED"

Now it works for all files.

I want my difftool and mergetool to be called only for files with names ending with .ext

EDIT:

I have added a file .git/info/attributes with the following contents:

*.ext   diff=difftool
*.ext   merge=mergetool

I've also added

[diff "difftool"]
    name = my custom diff driver
    driver = difftool.git.sh %A %B %O
[merge "mergetool"]
    name = my custom merge driver
    driver = mergetool.git.sh %A %B %O %A

to my .git/config.

Now I run

git difftool

It calls KDiff3 instead of my difftool. What do I do wrong?

Remark: I'm playing with difftool instead of mergetool because it is easier to test and I believe that if I manage to configure difftool, it will be obvious for me how to configure mergetool.

EDIT:

Difftool now works.

.git/config:

[diff "difftool"]
    command = difftool.git.sh

.git/info/attributes:

.ext diff=difftool

difftool.git.sh (in PATH)

#!/bin/sh
difftool.jar "$2" "$5"

But there is a side-effect on Windows: git diff now results in APPCRASH.

EDIT:

I have figured out how to avoid crashing or hanging of git diff: one should use git difftool or call git diff through sh: sh -c "git diff"

like image 561
utapyngo Avatar asked Sep 13 '11 13:09

utapyngo


People also ask

How do I set up Mergetool?

git mergetool is fully configurable so you can pretty much chose your favourite tool. In brief, you can set a default mergetool by setting the user config variable merge. tool . If the merge tool is one of the ones supported natively by it you just have to set mergetool.

What is git Mergetool command?

Use git mergetool to run one of several merge utilities to resolve merge conflicts. It is typically run after git merge. If one or more <file> parameters are given, the merge tool program will be run to resolve differences on each file (skipping those without conflicts).


1 Answers

You would use a merge driver in a gitattributes file.

See for instance "How do I tell git to always select my local version for conflicted merges on a specific file?"

*.ext merge=mymergetool

You can use patterns in a gitattributes file.

like image 105
VonC Avatar answered Oct 07 '22 07:10

VonC