Home > other >  How to access commit hash instead of temp file path in git diff tool script
How to access commit hash instead of temp file path in git diff tool script

Time:03-06

I have the following configuration for git difftool:

[diff]
    tool = any
[difftool]
    prompt = false
[difftool "any"]
    cmd = /maxkoretskyi/test/my.sh "$LOCAL" "$REMOTE"

inside cmd I have access to several variables like $LOCAL and $REMOTE that I pass to my.sh. Those are temp file paths and my script outputs them simply like this echo "$1" "$2":

$ git difftool git difftool 821d1b06 73a14711
Temp/NviQKc_f1.txt 
Temp/exkQKc_f1.txt

Is there any way to access the commit hashes in my.sh that a user passes to `git difftool command?

CodePudding user response:

difftool is not what you want; this program operates on file contents, and has no access to metadata. Rather, look into the GIT_EXTERNAL_DIFF environment variable

Quoting from the manpage:

GIT_EXTERNAL_DIFF

When the environment variable GIT_EXTERNAL_DIFF is set, the program named by it is called to generate diffs, and Git does not use its builtin diff machinery. 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

  • Related