从分支中删除旧的Git提交而不使用反向修补程序? [英] Remove an old Git commit from a branch without using a reverse patch?
本文介绍了从分支中删除旧的Git提交而不使用反向修补程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
A - B - C - D - E - - HEAD
是否有任何命令删除旧提交并保留其他提交,如提交C ?
终于变成这样了
A - B - - D - E - HEAD
我知道我们可以使用反向修补程序并应用新的提交反向补丁以删除提交C,但树结构不会那么清晰,看起来很庞大,即
A - B - C - D - E - C(适用反向补丁) - HEAD
任何人都知道?
解决方案
使用交互式rebase。例如,要返回5次提交:
git rebase -i HEAD〜5
然后在弹出的编辑器中,删除包含要删除的提交的行。
I have a master branch like this..
A -- B -- C -- D -- E -- HEAD
Is there any command that remove one of a old commit and retain the others, say commit C?
finally it becomes like this
A -- B -- D -- E -- HEAD
I know that we can use a reverse patch and apply a new commit with reverse patch to remove commit C, but the tree structure will not be so clear and looks bulky, i.e.
A -- B -- C -- D -- E -- C(apply reverse patch) -- HEAD
Anyone knows?
解决方案Use interactive rebase. For example, to go back 5 commits:
git rebase -i HEAD~5
Then in the editor which pops up, delete the line containing the commit you want to remove.
这篇关于从分支中删除旧的Git提交而不使用反向修补程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文