How to get second last commit hash in git

git rev-parse @~

rev-parse turns various notations into hashes, @ is current head, and ~ is the previous commit.

This generalizes to commits arbitrarily far back: for example, you can write @~3 (or @~~~) to specify "three commits before the current head".


Use skip attribute
--skip=<number> skips number commits before starting to show the commit output.

git log -n 1 --skip 1 --pretty=format:"%H"

Follow this link for more info on git log

Tags:

Git