git代码回退

使用命令:

git reflog

git reset  --hard  commit id

 

命令演示:

# 首先查看本地所有的commit操作

git reflog

$ git reflog
38caa099035 HEAD@{0}: commit: add hsync feature
acf5215e691 HEAD@{1}: commit: add mput feature
b165c4fe8a7 (HEAD -> branch-2.7.2, tag: rel/release-2.7.2, origin/branch-2.7.2) HEAD@{2}: clone: from https://github.com/apache/hadoop.git

# 目前位于38caa099035(commit ID)的提交的代码状态下, 想恢复到b165c4fe8a7 提交时的代码

git reset  --hard b165c4fe8a7

再看下git reflog:

$ git reflog
b165c4fe8a7 (HEAD -> branch-2.7.2, tag: rel/release-2.7.2, origin/branch-2.7.2) HEAD@{0}: reset: moving to b165c4fe8a7
38caa099035 HEAD@{1}: commit: add hsync feature
acf5215e691 HEAD@{2}: commit: add mput feature
b165c4fe8a7 (HEAD -> branch-2.7.2, tag: rel/release-2.7.2, origin/branch-2.7.2) HEAD@{3}: clone: from https://github.com/apache/hadoop.git

可以看到恢复到了b165c4fe8a7提交时的代码。

你可能感兴趣的:(项目管理)