简体   繁体   English

如何将更改推送到具有冲突历史记录的git仓库?

[英]How do I push changes to a git repo with conflicting history?

I want to have a blessed repository and several group or developer repositories. 我想拥有一个受祝福的存储库和几个组或开发人员存储库。

Developers shall clone from the blessed repository work on that cloned repository and commit their changes. 开发人员应从克隆的存储库中的受祝贺的存储库工作中克隆并提交其更改。 Whenever they feel like their work is completed, they shall push their changes to their public repository. 每当他们觉得他们的工作已经完成时,他们就应该将他们的更改推送到他们的公共存储库。 Then the lead developer shall pull the changes from the public developer repository - do whatever he wants to do with it (sign off, modify, etc.) and then push it to the blessed repository. 然后,主要开发人员应从公共开发人员存储库中提取更改 - 执行他想要做的任何事情(签名,修改等),然后将其推送到受祝福的存储库。

分配工作流程

In any environment where code reviews count code might get rejected. 在任何代码审查计数代码可能被拒绝的环境中。 Assume developer A and B work on a feature at the same time. 假设开发人员A和B同时处理某个功能。 Both developers finish their work and push the patches to their public repository. 两位开发人员都完成了他们的工作并将补丁推送到他们的公共存 The patches of developer A get accepted while the patches of developer B are rejected. 当开发者B的补丁被拒绝时,开发者A的补丁被接受。 Then the lead developer pushes the changes of developer A to the blessed repository. 然后,首席开发人员将开发人员A的更改推送到祝福的存储库。 Developer B fixes the patches and rebases his work on top of the blessed repository (the accepted changes of developer A respectively). 开发人员B修复补丁并将其工作重新放在受祝福的存储库之上(分别是开发人员A接受的更改)。 If developer B pushes his work now to his public repository he will receive an error that the repositories have incompatible histories. 如果开发人员B现在将他的工作推送到他的公共存储库,他将收到一个错误,即存储库具有不兼容的历史记录。

The only way I could fix that was to delete the public repository and to recreate the repository. 我可以解决的唯一方法是删除公共存储库并重新创建存储库。 Is there a cleaner way to fix that? 有更清洁的方法来解决这个问题吗?

Considering the public repo has for only client the integration manager, B can safely force push his work: 考虑到公共回购只为客户提供集成经理,B可以安全地强行推动他的工作:

git push --force

The integration manager hasn't accepted any of B's commits, so B can rewrite the history of his commits and push them again. 集成管理器还没有接受任何B的提交,所以B可以重写他的提交历史并再次推送它们。
Would anyone else clone/pull from B's public repo, then a push --force wouldn't be considered an acceptable solution. 是否有人会从B的公共回购中克隆/拉出,然后push --force将不被视为可接受的解决方案。


The OP Alex added in the comments: OP Alex在评论中补充道:

So do I get that right? 所以我做对了吗? if anybody would pull from B the workflow is broken because the blessed repo isn't a strict ordered subset of B's ? 如果有人从B拉出来,工作流程就会被打破,因为受祝福的回购不是B的严格有序子集?

I replied: 我回答:

If anybody else pulled from B's public repo, then that history becomes public (which it is not in your scenario, since only the integration manager pulls, and don't even keep B's commits). 如果其他任何人从B的公共回购中撤出,那么该历史就会变成公开的(它不在您的场景中,因为只有集成管理器才会撤消,甚至不会保留B的提交)。
And you shouldn't rebase public history. 你不应该改变公共历史。 See Pro-Git book " the peril of rebasing " section 请参阅Pro-Git书籍“重新定位的危险 ”部分

So if I have a hotfix to push to the blessed repo I'd kill all the stuff from my public repo to be as close as possible to the blessed one? 所以,如果我有一个修补程序推送到受祝福的回购我会杀死我的公共回购中的所有东西,尽可能接近受祝福的回复? Or how would the lead then cherry pick hotfixes? 或者如何领导樱桃挑选修补程序?

If you have other stuff in your public repo which haven't been accepted yet, you could publish your hotfix in a dedicated ' hot_fix ' branch (that B has first rebased on top of blessed repo, and then pushed to B's public repo) , monitored by the integration manager just for that. 如果您的公共hot_fix还有其他尚未被接受的东西,您可以在专门的' hot_fix '分支中发布您的修补程序(B首先在祝福仓库之上重新定位,然后推送到B的公共仓库),由集成管理器监控。

Anyway, the point is: that integration manager always expects new commits on top of his existing set of commits, new history , not a conflicting history (because of a lack of rebase from B). 无论如何,重点是:集成管理器总是期望在他现有的提交集, 新历史记录之上进行新提交,而不是相互冲突的历史记录(因为缺少来自B的变更)。
Any conflicting history should be rejected, whatever the origin of the branch. 无论分支的起源如何,任何冲突的历史都应该被拒绝。

And beware of cherry-picking, it can lead to troubles. 并提防樱桃采摘,它可能导致麻烦。 See: 看到:

You can arbitrarily change the history in a public repository by using push -f to force update the remote. 您可以使用push -f强制更新远程来随意更改公共存储库中的历史记录。 Since the individual developer is the only one who should be changing their own public repository, this is normally a safe thing to do. 由于个别开发人员是唯一应该更改自己的公共存储库的人,因此这通常是安全的事情。

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

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