Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a nth git log in a branch

Tags:

git

git log -1 shows last commit and git log -2 shows last two commit ; How can get log for a single commit in history.

    commit 1
    commit 2
    commit 3
    commit 4

How to get just one commit in history so that I can see just commit 3, how to get lets say just

     commit 3

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

like image 977
Amit Avatar asked Sep 20 '13 12:09

Amit


People also ask

How do I get git logs?

The command for that would be git log –oneline -n where n represents the number up to which commit you to want to see the logs.

What is git log -- Oneline?

Git Log Oneline The oneline option is used to display the output as one commit per line. It also shows the output in brief like the first seven characters of the commit SHA and the commit message.

Does git log show all branches?

Many times it's useful to know which branch or tag each commit is associated with. The --decorate flag makes git log display all of the references (e.g., branches, tags, etc) that point to each commit.

What are the 40 character strings of letters and numbers that appear in git log called?

Those strings are actually not random; the string is the SHA-1 checksum of all the changes in that commit. "SHA" stands for Simple Hashing Algorithm. The checksum is the result of combining all the changes in the commit and feeding them to an algorithm that generates these 40-character strings.


2 Answers

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

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

will show the 4th-last commit starting from HEAD.

Another way of specifying the same revision is HEAD^^^^

like image 90
knittl Avatar answered Oct 12 '22 23:10

knittl


I know this is an old question, but since I came here from Google, and my question ("How to get a nth git log in a branch", but the way I understand it) was not answered here, here's how to find the nth commit if you don't count backwards:

git log -n 1 --skip $(expr $(git log --oneline | wc -l) - 1) # show the 1st commit
git log -n 1 --skip $(expr $(git log --oneline | wc -l) - 100) # show the 100th commit

I think you get the point.

like image 43
depoulo Avatar answered Oct 13 '22 00:10

depoulo