How to get back to most recent version in Git?

前端 未结 10 1055

I have recently moved from SVN to Git and am a bit confused about something. I needed to run the previous version of a script through a debugger, so I did git checkout <

相关标签:
10条回答
  • 2021-01-29 18:21

    You can check out using branch names, for one thing.

    I know there are several ways to move the HEAD around, but I'll leave it to a git expert to enumerate them.

    I just wanted to suggest gitk --all -- I found it enormously helpful when starting with git.

    0 讨论(0)
  • 2021-01-29 18:25

    A more elegant and simple solution is to use

    git stash
    

    It will return to the most resent local version of the branch and also save your changes in stash, so if you like to undo this action do:

    git stash apply
    
    0 讨论(0)
  • 2021-01-29 18:27

    Some of the answers here assume you are on master branch before you decided to checkout an older commit. This is not always the case.

    git checkout -
    

    Will point you back to the branch you were previously on (regardless if it was master or not).

    0 讨论(0)
  • 2021-01-29 18:31

    This did the trick for me (I still was on the master branch):

    git reset --hard origin/master
    
    0 讨论(0)
提交回复
热议问题