git:从公共分支删除重复的提交? [英] git: remove duplicate commits from public branch?

查看:248
本文介绍了git:从公共分支删除重复的提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以某种方式在分支中获得了一些重复的提交,每个都有相同的更改。这是一个公共分支,由几个用户从几个分支合并而成。我需要定期将这个分支重新分配到另一个回购的主分支,这些重复使得它很笨拙。



有没有办法去除这些分支并将它们推送给公众repo w / out对于从分支工作的其他用户来说很复杂吗?

解决方案

在这种情况下,filter-branch不是必需的正如Jefromi所提到的,没有让每个人都变得复杂一点,这是不可能的。 Git的第一条规则 - 不要重写已发布的历史记录。

如果你真的想清理已经搞砸了的分支,那么你应该在本地重新绑定它,重新安排提交并在必要时强制推送它到主线。为了做到这一点(假设分支在本地检出,并且最后一个已知的良好状态,在这之后,你已经开始获取这些重复的文件是20次提交前)

  git checkout yourPublicBranch 
git rebase -i HEAD〜20

这将触发编辑器,您可以在其中管理提交。然后,你将不得不保存文件并退出rebase开始工作。这可能会导致冲突。


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?

解决方案

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.

这篇关于git:从公共分支删除重复的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆