How do I undo a checkout in git?

后端 未结 3 497
南旧
南旧 2020-11-30 18:40

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

相关标签:
3条回答
  • 2020-11-30 18:50

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

    0 讨论(0)
  • 2020-11-30 18:58

    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.

    0 讨论(0)
  • 2020-11-30 19:06

    To undo git checkout do git checkout -, similarly to cd and cd - in shell.

    0 讨论(0)
提交回复
热议问题