18

だから私は前のコミットに戻るためにgit--resetsoftを実行しました。以前のコミットに戻りたい場合はどうすればよいですか?すなわち:最新のコミット?git logを試してみましたが、そこにリストされているコミットには最新のコミットがありませんでした。

4

2 に答える 2

41

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).

于 2012-07-13T23:52:48.350 に答える
27

Do you want to basically undo your reset? It's not going to show up in your git log because you reverted it from that. However it will show up in your

git reflog

This will give you a listing of all your different branches.

git reset HEAD@{1}

Should fix your problem if your reset was the last thing you did.

于 2012-07-13T23:39:22.020 に答える