撤销git merge/撤销git push

48 阅读1分钟

已git merge未git commit

git merge --abort

已git merge+git commit未git push

保留更改,仅回退提交,代码不变

git reset HEAD~1

彻底删除合并提交,丢弃所有更改代码

git reset --hard HEAD~1

已git merge+git commit+git push

git log 查询commitId
git revert -m 1 <merge-commit-hash>
git push origin <branch-name>

或者是(如果合并后没有其他提交,可以直接回退)
git reset --hard HEAD~1 
git push origin <branch-name> --force

撤销git push非合并push

git reset <commit-hash>   //回退到指定提交,保留更改
git reset --hard <commit-hash> //彻底丢弃之后的提交
git push origin <branch-name> --force

commit代码被覆盖/被删除,重新使用commit

git cherry-pick <commit-hash>  
如果有冲突解决冲突
git add. 
git commit -m 'Reapply commit-A'
git push