撤销 commit

详细步骤

  • git log命令查看提交信息,获取要撤销的版本号
git log
  • git reset –mixed <版本号> 重置到指定版本的提交
git reset --mixed [版本号]
+ git reset的三种方式
  • 使用 mixed, 只会清空暂存区与本地库(撤销 git commit, 撤销 git add),工作区代码(编辑器改动代码)依然保留.
  • 使用 soft, 撤销git commit,不撤销git add,保留编辑器改动代码.
  • 使用 hard, 本地代码也会消失(撤销 git commit,撤销 git add,删除编辑器改动代码).
  • git push origin master –force 通过强制提交当前版本号到线上,以便达到撤销版本号的目的
git push [远程库地址别名] [分支名] --force

撤销 push

详细步骤

  • git log命令查看提交信息,获取要撤销的版本号
git log
  • git reset –soft <版本号> 重置到指定版本的提交
git reset --soft [版本号]
  • git push origin master –force 通过强制提交当前版本号到线上,以便达到撤销版本号的目的
git push [远程库地址别名] [分支名] --force
  • 修改代码提交
git add .
git commit -m "注释"
git push origin master