0

If HEAD points to the latest tip of the repository, how could I get reference to the very beginning of a repository in a similar fashion?

altern
  • 5,829
  • 5
  • 44
  • 72
  • There's nothing built in - indeed, there can be more than one "orphan" commit (a commit without parents) - just `git checkout --orphan` - and any could claim to be a "root" – canton7 May 20 '21 at 21:09
  • 1
    Might be a duplication of https://stackoverflow.com/questions/1006775/how-to-reference-the-initial-commit – Mark Bramnik May 20 '21 at 21:13
  • 1
    For some purposes you can use the all-zeros hash to refer to *before* the first commit ... – o11c May 20 '21 at 21:17

2 Answers2

2

This link might help.

In short, git rev-list --max-parents=0 HEAD worked for me.

tanmoy
  • 1,276
  • 1
  • 10
  • 28
  • This is very good, actually.... but it's not bullet-proof. There are a number of gotchas: different branches could have different starting points (something perfectly possible with git)... or a branch could have more than one starting point. Upvoted, just in case. – eftshift0 May 20 '21 at 21:48
1

There is not such a thing. You can have multiple unrelated branches each one with their own starting revision (actually, a single branch can have multiple starting revisions... if there was a merge of unrelated histories, for example).

As a side note, HEAD, unlike svn, is not the tip of the repo. HEAD is wherever you are standing, not necessarily the last revision of a branch... and what does all of that mean?

git checkout main~5

So, you are 5 revisions behind main... well, that's where HEAD is.

eftshift0
  • 26,375
  • 3
  • 36
  • 60