2

I want to get the commit hash of the very first commit within a git repository.

Sounds easy enough, but I am struggling to find the right git command to do this.

Super Man
  • 106
  • 1
  • 8

1 Answers1

4

I think this is a duplicate of this How to reference the initial commit? but to help you directly:

You are looking for this command

$ git rev-list --max-parents=0 HEAD
George V.
  • 140
  • 5
  • yes, that's exactly what I was looking for. I did browse around but couldn't find what I was looking for, guess i was using the wrong search term, using "first commit" as opposed to "initial commit". but thanks for your quick response. I was stuck on this for some time now. – Super Man May 20 '20 at 02:59
  • 1
    Note that it's possible for a repository to have more than one root commit, and this could traverse to some or all of them. That's pretty rare though. It's represented by getting more than one hash ID from the above query. (You will always get at least one, in a non-empty repository where `HEAD` is valid.) – torek May 20 '20 at 06:06