To reference a commit, simply write its SHA-hash, and it'll automatically get turned into a link.
Usually the first commit is named "Initial commit". As best practice its include a README file describing the project. The README is usually is a md file. You can put any code you wish as well.
You can just reverse your log and just head it for the first result. git log --reverse reverses the history, so you have to use head -1 instead of tail -1 to get the first commit.
Do not use git-log for scripting: use either git-rev-list
, or git-log
with specified custom format (--format=*<sth>*
option).
There is additional problem with your question: there can exist more than one such TAIL root commit (parentless commit) in a repository (even if we discount disconnected branches, such as 'html', 'man' and 'todo' in git.git repository). This is usually result of joining separate projects in one, or using subtree merge of separately developed subproject.
For example git repository has 6 root commits: git-gui, gitk (subtree-merged), gitweb (merged in, no longer developed separately), git mail tools (merged very early in project history), and p4-fast-export (perhaps accidental). That is not counting roots of 'html and 'man' branches, "convenience" branches which contains pre-generated documentation, and 'todo' branch with TODO list and scripts.
If you have git 1.7.4.2 or newer, you can use the --max-parents
option:
$ git rev-list --max-parents=0 HEAD
Otherwise, you can get list of all parentless (root) commits accessible from current branch using:
$ git rev-list --parents HEAD | egrep "^[a-f0-9]{40}$"
git rev-list HEAD | tail -n 1
is a more stable option.
Not sure what you're trying to do here, but some git commands take --root
as an option, in order to reference the root of the commit tree, e.g.
git rebase --interactive --root main
Assuming the first parent of a merge is the main line of development:
git rev-list --reverse --topo-order --first-parent HEAD | sed 1q
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With