'How to show the first commit by 'git log'?

I have a Git project which has a long history. I want to show the first commit.

How do I do this?

git


Solution 1:[1]

I found that:

git log --reverse

shows commits from start.

Solution 2:[2]

You can just reverse your log and just head it for the first result.

git log --pretty=oneline --reverse | head -1

Solution 3:[3]

git log $(git log --pretty=format:%H|tail -1)

Solution 4:[4]

To see just the commit hash of the first commit:

git rev-list --max-parents=0 HEAD 

To see the full git log, with commit message, for just the first commit:

git log $(git rev-list --max-parents=0 HEAD)

To see all git log messages in reverse order, from the first commit at the top (instead of at the bottom) to the last (most-recent) commit at the bottom (instead of at the top):

git log --reverse

References:

  1. How I learned the first command above: [the accepted answer] How to show first commit by 'git log'? (the 2nd command above was my own contribution)
  2. I learned about git log --reverse from the most-upvoted answer, by @Nyambaa

Solution 5:[5]

Not the most beautiful way of doing it I guess:

git log --pretty=oneline | wc -l

This gives you a number then

git log HEAD~<The number minus one>

Solution 6:[6]

git log --format="%h" | tail -1 gives you the commit hash (ie 0dd89fb), which you can feed into other commands, by doing something like

git diff `git log --format="%h" --after="1 day"| tail -1`..HEAD to view all the commits in the last day.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 the Tin Man
Solution 2
Solution 3 Matthew Flaschen
Solution 4
Solution 5 MHC
Solution 6 TankorSmash