How to get the nth git log in a branch

git log -1 shows the last commit and git log -2 shows the last two commits; How to get a magazine for one commit in history.

commit 1 commit 2 commit 3 commit 4 

How to get only one commit in history, so that I can only see commit 3, how to get allows you to say simply

  commit 3 

if I know the hash, then I can use git show to get it, how can we get the last nth commit without knowing the hash.

+6
source share
3 answers

You can specify a version in the past using the suffix ~ :

 git show HEAD~4 git log -1 HEAD~4 

will show the fourth-last fixer starting with HEAD.

Another way to specify the same revision: HEAD^^^^

+7
source
 git log -1 --skip=n 

will skip the first n-commits and just show 1 commit

+8
source

You can use git show with a relative link that visits the head parents:

 git show head~2 
0
source

Source: https://habr.com/ru/post/954251/


All Articles