git的回退

2019-05-12  本文已影响0人  黄靠谱

git的文件状态

另外 version control / log会显示 origion/master 表示上一个commit、push点的状态

业务场景,如果你写的代码,你想撤销掉

  1. 你的代码还没有commit,那么直接revert就可以恢复代码了
  2. 你的代码已经commit,但是还没push。 那么就要reset current branch to this here,而且是 hard模式
  3. 你的代码已经commit了,而且已经push了。那么先reset到要还原的push点,然后 git push --force 。谨慎使用,小心被打,因为别人push的代码也会被从remotes中清除掉。

场景1:

修改了文件(新增、删除、修改),要恢复到上次commit点
直接通过项目 git -- revert--撤销掉修改即可

场景2:

代码commit到本地仓库,还没有push到远程仓库,这时要回退代码,也就是恢复代码到上一个push点
version contral -->log -->reset current branch to this here --> force checkout to hard set ,就会强制切换到 之前的版本。
所有的commit,选择hard set

注意:这个只能回退未push的代码啊

场景3:

代码push到了远程仓库,如何撤销push
先reset current branch ,再用命令 git push --force

默认idea里面的git是不支持你这样操作的,因为太过危险了,除非你专门配置了 git allow force push

上一篇下一篇

猜你喜欢

热点阅读