How to cancel checkout in git?

I just checked an earlier commit from my local git repository. I did not make any changes to this, I just looked at him. Now I want to return to my last commit - how do I do this?

The exact command I used to check:

git checkout e5dff6b3c5d704f9b598de46551355d18235ac08 

Now, when I type git log, at the top, I see that this check latch, but none of my last commit. Did I accidentally delete them?

+73
git
Aug 30 '10 at 15:39
source share
3 answers

Try it first:

 git checkout master 

(If you are on a branch other than master , use the branch name there instead.)

If this does not work, try ...

For a single file:

 git checkout HEAD /path/to/file 

For the entire working copy of the repository:

 git reset --hard HEAD 

And if this does not work, you can look in the reflog to find your old SHA and reset for this:

 git reflog git reset --hard <sha from reflog> 

HEAD is a name that always indicates the last commit in your current branch.

+125
Aug 30 '10 at 15:41
source share

To cancel git checkout do git checkout - , similar to cd and cd - in the shell.

+16
Jun 02 '16 at 11:11
source share

You probably want git checkout master or git checkout [branchname] .

+10
Aug 30 '10 at 15:45
source share



All Articles