7

if i got into tig main view, i get a nice graph of commits and merges. i'd prefer to just look at the merge commits to trunk but unlike with normal commits tig where tig shows the full diff with file contents, on merge commits it just shows a list of changed files in the diff view. How do i get tig to display the file contents diff on merge commits?

commit fb56223ec50cf659a308b3c9979c912881147689
Refs: [master], {origin/master}, {origin/HEAD}, juju-1.21-alpha1-229-gfb56223
Merge: 7e7c95d a017b5a
Author: Juju bot
AuthorDate: Mon Sep 22 01:22:03 2014 +0100
Commit: Juju bot
CommitDate: Mon Sep 22 01:22:03 2014 +0100

Merge pull request #803 from mjs/check-ssh-api-methods-are-allowed-during-upgrade

cmd/juju: ensure that API calls used by "juju ssh" are allowed during upgrades

We recently had a regression where an API call required by "juju ssh" wasn't being allowed by the API server while upgrades are in progress. "juju ssh" is one of the few commands that is supposed to work during upgrades.                                                  

The Client used by "juju ssh" is now forced into an interface and this is checked using reflection against what the API server will allow during upgrades. Effectively, the compiler helps to check that the required API methods will be allowed.

http://reviews.vapour.ws/r/64/diff/                                                                                                                                                                                                                                           

apiserver/upgrading_root.go | 20 +++++++++++---------
cmd/juju/ssh.go | 15 +++++++++++----
cmd/juju/ssh_test.go | 24 ++++++++++++++++++++++++
3 files changed, 46 insertions(+), 13 deletions(-)

navigating to the individual files (j/k) in the view, says press 'Enter' to view file diff, but hitting enter gets "Failed to find file diff" err message. ideally i'd just be looking at the combined diff for the merge commit.

[update] i traced through tig with sysdig and it looks like its doing the following which on merge commits won't show the actual diff. git show --encoding=UTF-8 --pretty=fuller --root --patch-with-stat --show-notes --no-color fb56223ec50cf659a308b3c9979c912881147689 --

i guess what i'm looking for on merge commits then is to parse the parents commits and then do something like the following git diff 7e7c95d a017b5a

[update] so the diff actually isn't correct here as that diff would be between the two parents, and be more inclusive of changes then the merge itself, the best content rendering of the diff seems to be

git diff fb56223^ fb56223

kapilt
  • 264
  • 1
  • 6

2 Answers2

9

Turns out this is pretty straightforward via external command integration.

I dropped this into ~/.tigrc:

bind diff 7 !git diff %(commit)^ %(commit)

and now just press 7 for the diff output i'm looking.

Tim Abell
  • 11,186
  • 8
  • 79
  • 110
kapilt
  • 264
  • 1
  • 6
2

The underlying Git command for displaying diffs in Tig is git-show. By default, it doesn't show the diffs of merge commits. This can be changed using the flag --diff-merges, using for example --diff-merges=m or -m for short (they represent the same flag).

This can be accomplished in two ways:

Put this into your .tigrc

set diff-options = --diff-merges=m

you can set many options in ~/.tigrc, see also the manpage:

man tigrc

Start tig with the option -m

tig -m

Options to tig are passed to the underlying git command. More Info about this also in the manpage:

man tig

Note that there are several other options for how git-show can display the diff of merge commits.

git show -m
git show -c
git show --diff-merges=1
...
CervEd
  • 3,306
  • 28
  • 25
MartinF
  • 109
  • 6
  • This is the real answer. Thanks! (and now SMH wondering why I didn't think to `man tig`, then checked the man page, but it doesn't mention `-m` or what diff options are available, for that you have to `man git-diff` which only mentions `-m` in a random note and not with all the other options it lists) – Shadow Man Aug 02 '23 at 19:30
  • @ShadowMan `-m` is not for `git-diff` but `git-show`. Sadly, for me, this is noticeably sluggish – CervEd Aug 29 '23 at 12:09
  • This is the correct answer. It's worthwhile mentioning `--diff-merges=1`, at least for me it's much snappier and it suits my needs better – CervEd Aug 29 '23 at 12:23