Harry Harry - 1 month ago 8
Git Question

How can I get second or third commit id?

I want to get specific git id in history.
I know how to do it only for the latest one:

$ git log -n 1 --format=%H


But how can I get the
n
th most recent commit?

Answer

Get i'th most recent commit using tail:

git log -n i --format=%H|tail -n 1

Example (get 10th commit)

git log -n 10 --format=%H|tail -n 1


A git-only way:

git log --skip (i-1) -n 1 --format=%H

Example (get 10th commit)

git log --skip 9 -n 1 --format=%H