I have a Git project which has a long history. I want to show the first commit.
How do I do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Short answer
(from tiho’s comment. As Chris Johnsen notices,
--max-parentswas introduced after this answer was posted.)Explanation
Technically, there may be more than one root commit. This happens when multiple previously independent histories are merged together. It is common when a project is integrated via a subtree merge.
The
git.gitrepository has six root commits in its history graph (one each for Linus’s initial commit, gitk, some initially separate tools, git-gui, gitweb, and git-p4). In this case, we know thate83c516is the one we are probably interested in. It is both the earliest commit and a root commit.It is not so simple in the general case.
Imagine that libfoo has been in development for a while and keeps its history in a Git repository (
libfoo.git). Independently, the “bar” project has also been under development (inbar.git), but not for as long libfoo (the commit with the earliest date inlibfoo.githas a date that precedes the commit with the earliest date inbar.git). At some point the developers of “bar” decide to incorporate libfoo into their project by using a subtree merge. Prior to this merge it might have been trivial to determine the “first” commit inbar.git(there was probably only one root commit). After the merge, however, there are multiple root commits and the earliest root commit actually comes from the history of libfoo, not “bar”.You can find all the root commits of the history DAG like this:
For the record, if
--max-parentsweren’t available, this does also work:If you have useful tags in place, then
git name-revmight give you a quick overview of the history:Bonus
Use this often? Hard to remember? Add a git alias for quick access
Now you can simply do