You can use git show
referencing the third parent from your current commit (i.e. the second ancestor from HEAD
). Also, git show
accepts the same format string as git log
:
git show HEAD~2 --pretty=format:"%h" --no-patch
Update (2016-12-01)
An even better way would be to use the rev-parse
plumbing command with the --short
option to output the abbreviated (7 characters) commit SHA-1:
git rev-parse --short HEAD~2
Or you could also specify the exact length of the commit SHA-1:
git rev-parse --short=4 HEAD~2