git reset --soft and going back to the latest commit

前端 未结 2 1298
北海茫月
北海茫月 2021-02-01 22:38

So I just did a git --reset soft to go back to a previous commit. Now what if I want to go back to the latest commit that I was at before? i.e: the latest commit? I tried doing

2条回答
  •  悲哀的现实
    2021-02-01 23:09

    git reset is the wrong tool to use if you just want to go back and look at an old commit, since in many modes it actually alters the history by removing commits, as you've discovered.

    If you want to temporarily get an old commit back in your working tree, just use git checkout. In this case, git checkout HEAD^ will take you back one commit. git checkout HEAD~3 will take you back three commits, and so on. Or you can give it the hash from git log.

    You can then return to the latest commit by doing git checkout master (replacing master with the name of any branch).

提交回复
热议问题