I just checked out an earlier commit from my local git repo. I haven't made any changes to it, I was just looking at it. Now I want to go back to my latest commit - how do I do that?
The exact command I used to check it out:
git checkout e5dff6b3c5d704f9b598de46551355d18235ac08
Now when I type git log, at the top I see this checked out commit, but none of my later commits. Did I accidentally delete those?
Try this first:
git checkout master
(If you're on a different branch than master
, use the branch name there instead.)
If that doesn't work, try...
For a single file:
git checkout HEAD /path/to/file
For the entire repository working copy:
git reset --hard HEAD
And if that doesn't work, then you can look in the reflog to find your old head SHA and reset to that:
git reflog
git reset --hard <sha from reflog>
HEAD
is a name that always points to the latest commit in your current branch.
要撤消git checkout
做git checkout -
,类似于cd
和cd -
在 shell 中。
您可能想要git checkout master
或git checkout [branchname]
。
If you are using github, chances are the name for default branch is no longer master
. Try git checkout main
instead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.