简体   繁体   English

Git rebase-删除一些已推送到远程存储库的提交

[英]Git rebase - delete a few commits that have been pushed to a remote repository

I coded a time-limited feature that has been merged to master and shipped to production. 我编写了一个限时功能,该功能已合并到母版并交付生产。 Now that the time is up, I'd like to remove the commits containing the feature from the code base. 现在时间到了,我想从代码库中删除包含该功能的提交。

Ordinarily I would do a git rebase -i and delete the commits. 通常我会做一个git rebase -i并删除提交。

However, these commits have already been pushed to the remote repository, so when I rebase locally and try to push the branch I get complaints about how the tip of my branch is behind, and can be fast-forwarded. 但是,这些提交已经被推送到远程存储库中,因此当我在本地进行基础调整并尝试推送分支时,我会抱怨分支的尖端如何落后并且可以快速转发。

Is there a way to generate a "new commit" from a rebase, to undo the commits I don't want? 有没有一种方法可以从基准库中生成“新提交”,以撤消我不需要的提交? I don't really care about having a "clean" commit history, any way to back out those commits would be great. 我并不真的在乎是否有“干净的”提交历史记录,任何回退那些提交的方法都是很棒的。

您必须git push --force分支到任何远程,因为默认情况下, push拒绝重写历史记录。

If you just want to get rid of the functionality (but not the history of the functionality) and it is all contained within a few specific commits (that don't affect other functionality) then git revert could be your answer. 如果您只是想摆脱功能(而不是功能的历史记录),并且全部包含在几个特定的​​提交中(不会影响其他功能),那么git revert可能是您的答案。

This isn't always a nicely usable option (for example the commits might include other functionality that you don't want removed), or you may have some compelling reason to want any trace of the functionality removed, but it's a handy command to be aware of. 这并不总是一个很好用的选项(例如,提交可能包含您不希望删除的其他功能),或者您可能有一些令人信服的理由希望删除该功能的任何痕迹,但这是一个方便的命令意识到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM