Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

github

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?

like image 998
Hum4n01d Avatar asked Apr 04 '17 02:04

Hum4n01d


People also ask

How do you jump to a specific commit git?

If you want to go to a particular commit of a git repository with submodules you can use 2 git commands: reset or checkout. You will also need to synchronise the submodules after the working directory has been altered as that doesn't happen automatically.

How do I find my first commit?

Click on the "Insights" tab of the repository that you want to see the oldest commit, followed by the "Network" sub-tab on the left menu bar. When the page is fully loaded (i.e. you can see lots of lines joining and all), press Shift + ← to go all the way to the first commit.

How do you squash first commit?

To squash the commits use git rebase to do an interactive rebase. For the example above where the last two commits have the same Change-ID this means an interactive rebase for the last two commits should be done. For further details about the git rebase command please check the Git documentation for rebase.


1 Answers

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)

like image 157
Harshit Garg Avatar answered Sep 25 '22 06:09

Harshit Garg