Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to update to a specific commit in git?

Tags:

git

I am new to git and I would like to know if I can update my local repository to a specific commit. Is this possible using checkout?

git checkout <commitId>

exp

git checkout 55215860452c5c6fb11eac6f51d63abb187e7

Thanks in advance!

like image 854
Nelly Junior Avatar asked Jul 05 '17 13:07

Nelly Junior


2 Answers

Yes, you can use git checkout <sha1>.

As stated in the comments, you can use:

  • The full SHA1 hash of the commit
  • Any prefix of the SHA1 that isn't ambiguous
  • Any ref that also points to this specific commit
like image 168
rdurand Avatar answered Sep 30 '22 13:09

rdurand


It depends on what you mean by "update my local repository". If you want to remain on your current branch, you can reset your branch to a prior commit with:

git reset --hard <SHA1>

This will put the state of your branch to that of SHA1. The command git checkout changes the branch you are working on, so it will also change the state of the local repository, but the branch will no longer be the same.

like image 34
JSeven Avatar answered Sep 30 '22 13:09

JSeven