How to Reference the Initial Git Commit
This Git tutorial will provide you the best and appropriate explanation concerning the question of referencing the initial commit in a git repository.
In some cases, you need to know the initial commit hash in a script. While Git uses <kbd class="highlighted">HEAD</kbd> to reference the latest commit, it does not have a direct reference to the first commit. Here, we will explain how to get the initial commit hash.
Referencing the initial commit
To get the initial commit hash in your script, use <kbd class="highlighted">git rev-list</kbd> instead of git log:
git rev-list
git rev-list --max-parents=0 HEADA repository can have more than one root commit. This typically occurs when merging separate projects or using subtree merges.
The git log Command
While git log is used to view and filter commit history, it does not directly output the initial commit hash without additional flags. For scripting purposes, git rev-list is more efficient and reliable.