对于已经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)撤销指定的版本,撤销也会作为一次提交进行保存。

推荐文章

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: