Using Custom Diff Tool with `Git Show`
With Git I Can Set a Custom Diff Tool That Is Used for Certain File Extensions by the Following In. Git/Config [Diff "Csv_Diff"] Command = Tools/Csv_Diff and...
With git I can set a custom diff tool that is used for certain file extensions by the following in .git/config
[diff "csv_diff"]
command = Tools/csv_diff
and this in .gitattributes (in the root of the repository)
*.csv diff=csv_diff
This works when using git diff, but it doesn't work with git show. My question is, how do I use a custom tool with git show?
4 Answers
Looks like you're looking for the --ext-diff option.
Here's what git show docs say about it:
--ext-diff
Allow an external diff helper to be executed. If you set an external diff driver with
gitattributes, you need to use this option withgit-logand friends.
Like @LucasTrzesniewski said, you can use --ext-diff from the command line to set a diff for the current session.
You can also use the .gitattributes to set the git-diff perfile.
A git diff implementation exists of 2 parts:
- A definition in
$GIT_DIR/configor$HOME/.gitconfig - A bound between a file and a definition in
gitattributes
Git has choosing for this design to separate the executable code from the source code, this makes it impossible for a git clone or other git command to run any harmful code.
Must Read
Writing a definition
To write a definition, we start with a header consisting of [diff "namehere"], then followed by a line-break.
The next line consists of the command definition, this line is as follows: command = commandlinehere. This command is then called with 7 arguments if it is ran, these are documented for the GIT_EXTERNAL_DIFF enviroment vriable in the docs.
GIT_EXTERNAL_DIFFWhen 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_DIFFis called with 7 parameters:path old-file old-hex old-mode new-file new-hex new-mode where:<old|new>-file are files GIT_EXTERNAL_DIFF can use to read the contents of <old|new>,
<old|new>-hex are the 40-hexdigit SHA-1 hashes,
<old|new>-mode are the octal representation of the file modes.
The file parameters can point at the user’s working file (e.g. new-file in "git-diff-files"), /dev/null (e.g. old-file when a new file is added), or a temporary file (e.g. old-file in the index).
GIT_EXTERNAL_DIFFshould not worry about unlinking the temporary file, it is removed whenGIT_EXTERNAL_DIFFexits.For a path that is unmerged,
GIT_EXTERNAL_DIFFis called with 1 parameter, <path>.For each path
GIT_EXTERNAL_DIFFis called, two environment variables,GIT_DIFF_PATH_COUNTERandGIT_DIFF_PATH_TOTALare set.
The total example looks like this:
[diff "jcdiff"]
command = j-c-diff