How do you jump to the first commit in git? [duplicate]
Asked Answered
P

1

24

How can I jump to the first every commit in a git repository? Also, is there a way to do it on Github through the website?

Putnam answered 4/4, 2017 at 2:1 Comment(0)
S
54

To go the first commit of the repo, do

  1. git checkout master
  2. git log --reverse
  3. The first entry in the output is the first commit.
  4. you can switch to that commit by git checkout <SHA-1>, where is the SHA of the commit(first one) Also, when you do git log you can easily navigate to the last entry to see the first commit.

All this can also be done in single command like git checkout `git rev-list --max-parents=0 HEAD | tail -n 1` which means to switch to the last commit having no parent from the current HEAD

Note: if you used --depth option, you might not be able to see the actual first commit, to avoid this ensure you clone the full repo (without --depth option)

Sander answered 4/4, 2017 at 2:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.