Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting back to the latest commit in git after checkout [duplicate]

Tags:

git

I ran the git log --oneline command and then ran the git checkout <commit-id> of some previous commit. I got the message that the "HEAD is now in the detached state...". Now I do not know how to get back to the latest commit. What is the command to get back to the latest commit. And when do we use this feature to checkout a previous commit version. Please let me know as I ran the checkout command while I was exploring git. Also how can we know to which commit the HEAD is pointing to?

like image 639
zilcuanu Avatar asked Nov 27 '25 21:11

zilcuanu


1 Answers

To return to your 'latest' commit checkout the branch you were working on. Either

git checkout master

or any other branch

git checkout <my_branch>

Checking previous commit or any commit which is not in a branch gets you in Detached HEAD state. This is valid state in git. Your working directory is updated and you can develop. What you cannot do in this state is perform commits. If you want to continue developing from some historical you can branch out from there. Example:

git checkout <some_hash_in_the_past>
... Detached head
git branch <my_new_branch>
... edit files
git add/commit
like image 153
Igal S. Avatar answered Nov 29 '25 09:11

Igal S.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!