3

I'm exploring git after having used svn and am having difficulty finding an equivalent for svn log --diff --diff-cmd=meld to show the log and for each commit open the diff tool (here meld)

Does one exist?

  • git log -p seems to be most of the way there, but doesn't appear to have a --tool= option
  • git difftool doesn't appear to have an easy mechanism to show the incremental changes along a date/commit range
1
  • I use the custom pager delta which interprets and enhances diff output from e.g. git-log(1) Commented Oct 15, 2024 at 11:52

1 Answer 1

0

No need to have that wired into git, as you can trivially compose that behaviour out of classic posix tools:

git log [...] --pretty=%H | xargs -L1 git show

This will run git show one-by-one on every commit of whatever commit range you specify in [...] (study the Specifying Ranges section of gitrevisions(7) manpage). Of course, you can also substitute any command whatsoever into that xargs call, or even write an explicit | while read line; do echo Buzzing $line; done loop. Because of --pretty=%H, we're feeding commit hashes into the pipe, one per line, and -L1 makes xargs call git show <sha> on every <sha> from the pipe input.

The default git show will respect the PAGER environment variable; export PAGER=less is one common choice, but I'm enjoying another one called bat, for example.


I hope that answers your need already. A few more tips / suggestions.

On large commit ranges, you might prefer to review simply git log [...] -p in a single pager instance — instead of running your pager N times. Pressing q to quit it once, is less annoying than pressing q N times. Search (using /) will also work better.

If you insist on viewing diffs in a GUI, consider learning & configuring an IDE integration or a standalone git client. That might work better for you than trying to support your workflows with hybrid CLI+GUI concoctions.

Having said that, you can of course view your diffs in meld while continuing to operate git cli. Git has a concept of difftool — see this question for guidance: Setting up and using Meld as your Git difftool and mergetool

There're even dedicated difftools that enhance reading of the unified diff syntax (as opposed to the split-diff two-panel format in Meld): diff-so-fancy, delta, likely more. See those repositories' readmes to preview what they do, install and configure into git cli. It's as easy as a snippet in gitconfig like this:

#-- https://github.com/so-fancy/diff-so-fancy
[core]
        pager = diff-so-fancy | less --tabs=4 -RFX
[interactive]
        diffFilter = diff-so-fancy --patch
[diff-so-fancy]
        stripLeadingSymbols = false
        markEmptyLines = false

— and yes, that integrates nicely into git show.

Lastly: I find Meld to be especially useful in the 3-way-diff mode, when resolving conficts during merge or rebase. That's almost the same concept; it's called a mergetool.


git difftool doesn't appear to have an easy mechanism to show the incremental changes along a date/commit range

That's orthogonal to what difftools do; filtering commit ranges is the job handled by git log. Please study the Specifying Ranges section of gitrevisions(7) manpage.

3
  • Your xargs(1) line looks equivalent to git show --do-walk. I don’t understand why you start with that section when the more relevant part is at the end where you configure the pager. And then git-show(1) becomes very secondary since you get the same diffing capability from git-log(1). Commented Oct 16, 2024 at 13:07
  • You're right @Guildenstern; that's to explain the absence of literal analogue to --diff-cmd that OP inquired about ... it's kind of unnecessary. And to hint at how trivial it is to DIY automate things like this with a little pipe. There's no exact same "easy mechanism" built-in — yet, it's dead easy to roll you own. I hope I'm not tiring anyone with reading through a pageful of text!
    – ulidtko
    Commented Oct 16, 2024 at 16:24
  • 2
    Coming back to this after using git more, it seems git show --ext-diff was what I was after, which combined with your xargs and @Guildenstern 's --do-walk greatly simplifies this transition to git. Many thanks!
    – Silas
    Commented Mar 28 at 14:35

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.