简体   繁体   中英

How to diff a commit?

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 )

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

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?)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM