当前位置:   article > 正文

git版本回退:revert回退其中一个提交/reset回退到某个版本_git代码回退到某一次提交

git代码回退到某一次提交

 

对于已经push或没有push的,回退commit方式一致。只是最后push 的时候 ,如果修改了已经push 的commit,那么需要使用git push -f

区别:git reset commitID;  回退到某个版本。中间的版本都会回退。

           git revert commitID; 只将commitID的代码回退。中间的版本不变。且会形成一条commit 记录。

  1. // 方法一 回退到某个版本
  2. git reset --hard commitID //不保留代码,直接回退。
  3. git push //直接推送
  4. // 方法二 回退到某个版本
  5. git reset --soft commitID //代码回退到工作区
  6. 修改代码
  7. git add .
  8. git commit -m 'xxx'
  9. git push
  10. // 方法三 只回退某个版本的修改
  11. git revert commitID
  12. git push

操作示例:

 

知识点:

* git revert HEAD 撤销前一次 commit
* git revert HEAD^ 撤销前前一次 commit
* git revert commit (比如:fa042ce57ebbe5bb9c8db709f719cec2c58ee7ff)撤销指定的版本,撤销也会作为一次提交进行保存。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/384796
推荐阅读
相关标签
  

闽ICP备14008679号