如何从分支的中间删除提交 [英] How to remove a commit from the middle of a branch
问题描述
我进行了一些提交,并将其推送到我的远程仓库中.我要删除的其中之一.它仅包含一个二进制文件,该二进制文件仅在该分支的该提交中被更改.如何删除它而对以后的提交没有危害?
I've made some commits and have pushed it to my remote repo. One of those I want to remove. It includes only one binary file, which was changed only in that commit in that branch. How to remove it without harm for later commits?
推荐答案
您可以使用interactive (-i) rebase
删除以前的提交.
You can use interactive (-i) rebase
to remove a previous commit.
$ git log # copy the target commit
$ git rebase -i <target-commit>~1 # start rebase from the previous commit of target commit
编辑器将打开一个提交列表,每行一个.每行以pick
开头. 注释掉目标提交行(在目标提交行的开头放置#
).
An editor will open with a list of commits, one per line. Each of these lines begins with pick
. Comment out your target commit's line (Put #
at the start of target commit line).
或者,放置drop
或d
而不是用 #
注释掉该行.
OR, put drop
or d
instead of commenting out the line with #
.
$ git rebase --continue # repeat the command until finish rebase
现在,由于git历史记录已更改,您需要强制(-f)推送到远程!
Now, you need to do force (-f) push to remote since git history has been changed!
$ git push -f origin HEAD
这篇关于如何从分支的中间删除提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!