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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With