A root commit (there can be more than one) is a commit with no parents.
This finds the root commit of the current commit (basically, "root of current branch" except that it works even with a detached HEAD):
git rev-list --max-parents=0 HEAD
This finds all root commits on all branches:
git rev-list --max-parents=0 --branches
and of course you can use --tags
or --all
instead of --branches
.
Usually there's only one root in a repository so that all of these find the same revision, and rev-list
prints revisions in a suitable order by default, so manojlds' answer will generally also work.
Edit: and of course, you have to provide the resulting SHA-1 to git reset
.