git:从公共分支中删除重复的提交?

发布于 2024-11-03 05:17:31 字数 153 浏览 3 评论 0原文

我以某种方式在分支中得到了一些重复的提交,每个提交都有相同的更改。它是一个公共分支,由多个用户从多个分支合并而成。我需要定期将此分支重新设置到另一个存储库的主分支上,而这些重复项使其变得笨拙。

有没有办法删除这些并将它们推送到公共存储库,而不会使在分支工作的其他用户变得复杂?

I've somehow got some duplicate commits in a branch, each with the same changes. It's a public branch, merged from several branches by several users. I need to periodically rebase this branch onto the master branch of another repo, and these duplicates make it clumsy.

Is there a way to remove these and push them to the public repo w/out making it complicated for other users working from the branch?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

洛阳烟雨空心柳 2024-11-10 05:17:31

在这种情况下,过滤器分支是不必要的,恕我直言,正如 Jefromi 提到的,如果不让其他人的生活变得有点复杂,这是不可能的。 Git 的第一条规则 - 不要重写已发布的历史记录。

如果你真的想清理已经搞乱的分支,那么你应该在本地重新调整它的基础,重新安排提交,并在需要时将其强制推送到主线。

为了做到这一点(想象一下分支在本地签出,并且您开始获取这些重复项后的最后一个已知良好状态是 20 次提交前)

git checkout yourPublicBranch
git rebase -i HEAD~20

这将启动编辑器,您将能够在其中管理提交。然后您必须保存文件并退出以便变基才能开始工作。这可能会导致冲突。

filter-branch is not necessary in this case IMHO and as Jefromi mentioned without making life a bit complicated for everybody else it is impossible. First rule of Git - do not rewrite published history.

If you really want to cleanup the branch that has got messed up, then you should rebase it locally, rearrange commits and force-push it to mainline if needed.

in order to do that (imagine that the branch is checked out locally and the last known good state after which you have started to get those duplicates is 20 commits ago)

git checkout yourPublicBranch
git rebase -i HEAD~20

This will fire up the editor in which you will be able to manage the commits. Then you will have to save the file and exit for rebase to start working. That may lead to conflicts.

青柠芒果 2024-11-10 05:17:31

使用git filter-branch重写历史记录。这是 github 上的一个很好的介绍:

http://help.github.com/removing-sensitive-data /

Use git filter-branch to rewrite the history. Here's a good intro from github:

http://help.github.com/removing-sensitive-data/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文