使用 git-convert 回滚已经提交的 commit
当前文章内容迁移中,如有问题,请提交 issues 谢谢~~
一. 简介
git-revert
用于撤销某次指定提交的操作,被操作的版本,之前和之后的内容(包括 commit 和 history 都会被保留下来)
二. 用法
- 对当前版本进行回滚操作
git revert HEAD
- 对上一个版本内容进行回滚
git revert HEAD^
- 对指定版本进行回滚
git revert commit hashValue
三. git-revert 和 git-rebase 比较
git revert
是对之前commit
内容进行覆盖。而git reset
是直接删除指定的commit
。两个命令效果一致:
git-revert
与之前的旧分支合并时,不会有新旧commit
内容的冲突;git-reset
时,与旧分支合并时,旧分支的commit
会被引入,有可能会产生冲突。
git reset 是把
HEAD
向后移动了一下,而git revert
是HEAD
继续前进,只是新的commit
的内容和要revert
的内容正好相反,能够抵消要被revert
的内容。