git回滚代码

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

1、 git reflog

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

2、 git reset --hard version

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

3、 git log

  1. $ git log
  2. commit f68161540b8c3400c4ab4a35eef67039c732781d (HEAD -> master)
  3. Author: drunkdream <drunkdream@gmail.com>
  4. Date: Wed Apr 25 19:31:53 2018 +0800
  5. Site updated: 2018-04-25 19:31:25
COPY

4、 git push --force

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

Related Issues not found

Please contact @drunkdream to initialize the comment