赞
踩
对于已经push或没有push的,回退commit方式一致。只是最后push 的时候 ,如果修改了已经push 的commit,那么需要使用git push -f
区别:git reset commitID; 回退到某个版本。中间的版本都会回退。
git revert commitID; 只将commitID的代码回退。中间的版本不变。且会形成一条commit 记录。
- // 方法一 回退到某个版本
- git reset --hard commitID //不保留代码,直接回退。
- git push //直接推送
-
- // 方法二 回退到某个版本
- git reset --soft commitID //代码回退到工作区
- 修改代码
- git add .
- git commit -m 'xxx'
- git push
-
- // 方法三 只回退某个版本的修改
- git revert commitID
- git push
操作示例:
知识点:
* git revert HEAD 撤销前一次 commit
* git revert HEAD^ 撤销前前一次 commit
* git revert commit (比如:fa042ce57ebbe5bb9c8db709f719cec2c58ee7ff)撤销指定的版本,撤销也会作为一次提交进行保存。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。