I often use the following command to compare git commits:
git difftool -t meld --dir-diff 456e86fbe 040564acf
Today, for the first time, I experienced that it did not start meld. It did not say anything and just exited.
After a bit of surprise, I started guessing this means that the files in the two commits are identical - but I can't be sure.
Is there a way to persuade git difftool to verbosely inform you if the files in the two commits are the same? I know diff has --report-identical-files for this purpose, but I couldn't find anything similar in man git difftool.
Unfortunately, git difftool doesn't provide any option to know or print whether the given commits have identical content. However, you could use git diff --quiet --exit-code to print a message if the commits are identical. If they're not, you can launch git difftool.
The command would look something like this:
git diff --quiet --exit-code <commit1> <commit2> \
&& echo "No differences between commits" \
|| git difftool -t meld --dir-diff -y <commit1> <commit2>
However, this is quite a hairy command to type each time and not well parameterized. What you could do instead is to define an alias for the previous command that accepts two commits:
git config --local alias.my-difftool '!sh -c '\''git diff --quiet --exit-code "$1" "$2" && echo "No differences between commits $1 and $2" || git difftool -t meld --dir-diff -y "$1" "$2"'\'' -'
An example of its usage would be
git my-difftool HEAD HEAD~2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With