git回滚代码

有时我们需要回滚git上已经提交的代码,特别是已经提交到github上的代码。可以使用如下步骤:

1、 git reflog

$ git reflog
1bd6100 (HEAD -> master) HEAD@{0}: commit: Site updated: 2018-05-10 12:20:40
f681615 HEAD@{1}: commit: Site updated: 2018-04-25 19:31:25
78f096f HEAD@{2}: commit: Site updated: 2018-04-25 19:11:23
14b480b HEAD@{3}: commit: Site updated: 2018-04-24 20:01:27

2、 git reset --hard version

$ git reset --hard f681615
HEAD is now at f681615 Site updated: 2018-04-25 19:31:25

3、 git log

$ git log
commit f68161540b8c3400c4ab4a35eef67039c732781d (HEAD -> master)
Author: drunkdream <drunkdream@gmail.com>
Date:   Wed Apr 25 19:31:53 2018 +0800

    Site updated: 2018-04-25 19:31:25

4、 git push --force

$ git push --force
Total 0 (delta 0), reused 0 (delta 0)
To github.com:drunkdream/xxx.git
 + 1bd6100...f681615 master -> master (forced update)
分享