git - 在HEAD之前删除提交

时间:2015-09-05 20:01:06

标签: git git-commit

好的我是Git的新手,想知道如何在HEAD之前删除提交。例如 - :

commit foo (This is the HEAD)

commit bar (This is what I want to remove)

如何从此分支中完全删除commit bar,但保留commit foo

2 个答案:

答案 0 :(得分:4)

git rebase -i HEAD~2

会让您以交互方式删除提交

git rebase将删除该提交的所有引用并更改HEAD提交的ID。意味着如果人们从旧提交中分支出来可能会有问题

git revert <commitID>

可能是保存历史的更好方法

答案 1 :(得分:0)

另一种选择是在要删除的提交之前的提交中签出新分支:

git checkout -b new_branch HEAD~2

然后樱桃选择从另一个分支到新分支的提交:

git cherry-pick <hash of the other branch's HEAD>

图表看起来像这样:

* 6a59727 (HEAD, new_branch) foo
| * 15f07fd (master) foo
| * 6bba064 bar
|/  
* dec804e baz
相关问题