I'd like to define a shortcut "git diffn" with this behavior:
git diffn := git diff HEAD HEAD~1
git diffn 1 := git diff HEAD~1 HEAD~2
git diffn 2 := git diff HEAD~2 HEAD~3
...
First one is no problem, but I don't know to to make the rest.
What about:
git show
- shows the last commit
git show HEAD~1
- shows the last but one commit
git show <COMMIT SHA>
- shows you any commit
git whatchanged
- shows you which files changed against the git log
Figured it out myself. I've added to ~/.gitconfig this monstrosity:
[alias]
dn = "!sh -c 'if [ $# -eq 0 ] ; then git diff HEAD~1 HEAD ; else git diff HEAD~`expr $1 + 1` HEAD~$1 ; fi' -"
After this,
git dn
works, as well as
git dn 1
git dn 2
...
Surprisingly (to me), you can combine ~n
and ^
syntax, so this is how I was doing it:
a=1; git diff HEAD^~$a HEAD~$a
But there's a simpler way:
a=1; git log -p -1 HEAD~$a;
I find the extra commit info helpfully orienting, but you can customize that away. Note: the manpage notes some minor differences between this and diff's format, which might matter for non-human consumption.
[alias]
diffn = "!sh -c 'git log -p -1 HEAD~$1' -"
Doesn't work with omitted arg, so I guess an if
is needed for that.
BTW: found similar discussion here