2

I'm not entirely sure if this is an issue with git difftool, but when I use it with a custom difftool it shows random prefixes to the filename I'm diffing on both sides. uZl7iq_README.txt vs hO7k5f3_README.txt, for example. I'm pretty confident that left and right correspond to the first and second commit hashes that I provide to difftool, and of course a little investigation proves/disproves that, but it would be really nice if the prefix could reflect the either the branch name I provided or the commit it resolves to. Anyone know of a workaround?

Nickolai
  • 1,579
  • 2
  • 12
  • 19

1 Answers1

2

Maybe, depends on the details of the diff tool.

git diff is aware of Git and can look up the contents of particular revisions in Git on its own and display the filename from Git.

git difftool uses an external diff program of your choice. These programs know nothing about Git. git difftool writes the contents to be diffed to temp files. Then it runs a script to execute the diff program. $LOCAL and $REMOTE are the temp files to be diffed. $MERGED and $BASE are name of the file in Git. You can see these by using the echo difftool.

If there is a way to tell the diff program "diff $LOCAL and $REMOTE, but pretend they are actually called $MERGED", then yes, you can write a wrapper script which will display the Git filename.

Schwern
  • 153,029
  • 25
  • 195
  • 336
  • It seems like it would be possible to write a script that intercepts the call to the difftool and renames $LOCAL and $REMOTE appropriately, but how would the script know the commits to which local and remote refer to? – Nickolai Jul 11 '22 at 19:15
  • It seems other have looked but not found anything compelling, at least not a simple setting or parameter or one-liner that provides the desired behavior, https://stackoverflow.com/questions/71361761/how-to-access-commit-hash-instead-of-temp-file-path-in-git-diff-tool-script – Nickolai Jul 11 '22 at 19:37