Search code examples
gitdiffgit-diff

Alternative diff algorithm for special file extension for Git


I want to use an alternative diff algorithm for special file extension, e.g. ".java" and the standart diff algorithm for other files.

I can make it via .gitattributes file:

*.java diff=javadiffprogramm

and .gitconfig file:

[diff "javadiffprogramm"]
    command = pathToDiffProgram.

My question is what is the format of input parameters of "javadiffprogramm" and where it should output the result of diff? The result of diff has the format like "@@ -1,7 +1,6 @@...".

Some questions on this topic:


Solution

  • This is documented in the git man page as GIT_EXTERNAL_DIFF.

    GIT_EXTERNAL_DIFF

    When the environment variable GIT_EXTERNAL_DIFF is set, the program named by it is called, instead of the diff invocation described above. For a path that is added, removed, or modified, GIT_EXTERNAL_DIFF is called with 7 parameters:

    path old-file old-hex old-mode new-file new-hex new-mode
    

    The docs go on to explain what those parameters are.

    Output should be to STDOUT.