6

Let's say if I do a git log and see one commit with ID 280c5af57b02c41edbf947a0eed31c72e2839123

It seems that to see what changes are made in that commit, I can either do

git diff 280c5af57^ 280c5af57

or

git show 280c5af57

However, since I already set up opendiff as the diff tool (using the instruction on https://gist.github.com/bkeating/329690), the first command above will show it using opendiff, while the second command will use the diff on the command line.

Instead of using a Bash alias or function, is there a way to tell git to diff it without typing or pasting in the commit ID twice? (like svn diff -c 321234)

3
  • Does git diff 280c5af57b02c41edbf947a0eed31c72e2839123 not work for you? Commented Apr 25, 2014 at 20:14
  • @動靜能量 why don't you want to use a Bash or Git alias? Commented Apr 26, 2014 at 9:23
  • @Cupcake because if you tell me I can use moremore foo.txt foo.txt to show a file, I will ask, without using alias, can I just type in foo.txt once Commented Apr 27, 2014 at 9:43

2 Answers 2

6

git diff defaults to comparing against the working tree and/or index. The command that's built to compare trees straight out of the repo is git diff-tree. Try:

git diff-tree --ext-diff -p 280c5af
Sign up to request clarification or add additional context in comments.

5 Comments

Note that git diff-tree and git show both do something different (and generally sensible) with merge commits (controllable with -c, --cc, and -m). With plain git diff, you identify two specific trees, so the special actions for combined diffs are not applicable.
aha, but opendiff won't be used to diff it... only the command line diff
Ah. I see the docs say you have to turn that on explicitly. I don't use them, this should do the trick now if I'm reading it right.
git diff-tree --ext-diff -p 280c5af will still only use the command line diff (not opendiff)
Try export GIT_EXTERNAL_DIFF=/path/to/your/diff first. The docs say it consults that, it may be nobody taught it to also consult the config yet.
1

You could add something like this to your gitconfig:

[alias]
    changes = !sh -c 'git diff "$0^" "$0"'

Now you can run

git changes 280c5af57b02c41edbf947a0eed31c72e2839123

and you only have to specify the SHA (or whatever) once.

(This answer does feel kind of heavy. Does anyone have a solution that doesn’t jump through the !sh -c hoop?)

2 Comments

isn't this almost the same as using a bash alias?
@動靜能量 In some sense, yes. But this has the advantage that you’re typing git <something> <sha>, just like any other Git subcommand.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.