If only there was an easy way to find the first commit in a Git repository…

$ git rev-list --max-parents=0 HEAD
91938b105b3e4ed86......

That returns the SHA-1 hash of the first commit in the repo and you can use git show to actually see the commit details like this:

$ git show 91938b105b3e4ed86......

Or you can simply combine the commands:

$ git show `git rev-list --max-parents=0 HEAD`

This gets the job done, but it’s kind of ugly and in practice you need to map it to some Git alias or a shell alias to be able to use it effectively. Here’s the shell alias approach:

alias git-first="git show `git rev-list --max-parents=0 HEAD`"

At this point it’s time for the twist it our story. Turns out there’s a much simpler way to get to the beginning of your history:

$ git log --reverse

Reference:

  1. Git scm

My site is free of ads and trackers. Was this post helpful to you? Why not BuyMeACoffee