rkevx21 rkevx21 - 8 months ago 65
Git Question

git log show one commit id only

I need some help. It is possible to only show one commit id? Since git log -3 show the log from 1 - 3, I just want to show only 3. What possible command will match for it?

I use the command

git log -3 --pretty=format:"%h"

the result is


I only want to display the 1c76c5d only.

Answer Source

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

Alternatively, you can use the rev-parse plumbing command with the --short option to output the abbreviated (7 characters) commit ID:

git rev-parse --short head~2

Or you could also specify the exact length of the commit ID:

git rev-parse --short=4 head~2