目前我找到的最好的解决方案是
git reset --soft HEAD^2
保持想要的变化
git reset --mixed HEAD^
杀死不需要的提交
不幸的是,它将迫使我重新创建在我想要消失的提交之后所做的提交
目前我找到的最好的解决方案是
git reset --soft HEAD^2
保持想要的变化
git reset --mixed HEAD^
杀死不需要的提交
不幸的是,它将迫使我重新创建在我想要消失的提交之后所做的提交
尝试git rebase -i <target commit>^
然后,当出现要变基的提交列表时,删除要删除的提交的行。
例如,如果我有:
6e99176 most recent commit
60dd2f0 older commit
4c82808 even older commit
b980abe commit i want to remove
5b7254b oldest commit
我可以
git rebase -i b980abe^
并将呈现:
pick 6e99176 most recent commit
pick 60dd2f0 older commit
pick 4c82808 even older commit
pick b980abe commit i want to remove
# Rebase 50ce3f5..9ad75f8 onto 50ce3f5
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
如果您按照说明删除有问题的提交,然后保存并关闭文件,您将从 git 历史记录中删除该提交。