简体   繁体   English

预测功能分支在主分支中合并时的合并冲突

[英]Predicting merge conflicts between feature branches when they are merged in the master branch

Assume I have a master branch and 3 feature branches.假设我有一个主分支和 3 个功能分支。 At the end of a sprint all those features are ready and I want to merge them all to the master.在 sprint 结束时,所有这些功能都已准备就绪,我想将它们全部合并到 master。

merge feature1 into master => OK
merge feature2 into master => OK
merge feature3 into master => CONFLICTS!

No commits were added to the master but there is still a merge conflict because feature3 conflicts with feature1 and/or feature2.没有向 master 添加任何提交,但仍然存在合并冲突,因为 feature3 与 feature1 和/或 feature2 冲突。

Is there is tool to predict this merge conflict (to see which feature branches will create merge conflict)?是否有工具可以预测这种合并冲突(查看哪些功能分支会产生合并冲突)? If I could predict this, I could dicede to only merge feature1 and feature3 into the master branch.如果我能预测到这一点,我可以只将 feature1 和 feature3 合并到 master 分支中。

Thanks!谢谢!

The way to predict a merge conflict is to do the merge.预测合并冲突的方法是进行合并。 1 Use a temporary branch to do this: 1使用临时分支执行此操作:

git checkout -b test master
git merge feature1
git merge feature2
git merge feature3

If everything has gone well, the merges work.如果一切顺利,则合并工作。 You can now, if you like, use this final merge as the result for master itself, by doing a fast-forward operation to move master up to match test :现在,如果您愿意,可以使用此最终合并作为master本身的结果,通过执行快进操作将master向上移动以匹配test

git checkout master
git merge --ff-only test   # --ff-only means "fail if fast-forward is not possible"

or simply delete branch test if you don't want to do this and/or the merge failed.或者如果您不想这样做和/或合并失败,则只需删除分支test If the merge failed, use git merge --abort to back out of it, as in footnote 1, or git reset --hard (which does the same thing).如果合并失败,请使用git merge --abort退出它,如脚注 1 所示,或git reset --hard (执行相同操作)。 Then use git checkout master and git branch -D test :然后使用git checkout mastergit branch -D test

git merge --abort          # if needed
git checkout master
git branch -D test

The only reason to use a separate test branch above is to avoid having master move until we've done all three merges.使用上面单独的test分支的唯一原因是避免在我们完成所有三个合并之前让master移动。 But since branch names are private to each repository, there's never any requirement to do this: you can just do the merges, and then roll back (with git reset --hard ) to a previous state if you don't like the result.但是由于分支名称对每个存储库都是私有的,因此没有任何要求这样做:您可以只进行合并,然后如果您不喜欢结果,则回滚(使用git reset --hard )到以前的 state 。 Just don't git push the commits, or make them available to git fetch , until you have the result you like.只是不要git push提交,或者让它们可用于git fetch ,直到你得到你喜欢的结果。


1 You can do a test merge without committing, if you like, then use git merge --abort to pretend you never ran the test. 1如果您愿意,您可以在不提交的情况下进行测试合并,然后使用git merge --abort假装您从未运行过测试。 But this doesn't work when you need to do more than one merge, as in the case in your question.但是,当您需要进行多次合并时,这不起作用,就像您的问题一样。


Octopus merges章鱼合并

There is another option, though, which Git calls octopus merges .不过,还有另一种选择,Git 称之为octopus merges 。 (Note: You cannot do these using GitHub, and probably not with some other web interfaces.) To do an octopus merge that combines all three features into master at once: (注意:您不能使用 GitHub 执行这些操作,并且可能无法使用其他一些 web 接口。)进行章鱼合并,将所有三个功能一次组合到master

git checkout master
git merge feature1 feature2 feature3

If there are any conflicts, the octopus merge will fail.如果有任何冲突,章鱼合并将失败。

(I have never actually used octopus merges in real work. They don't achieve anything you cannot do with regular merges, and people find them confusing, so I tend to stick with the regular merges.) (我从未在实际工作中真正使用过章鱼合并。它们无法实现常规合并无法做到的任何事情,而且人们发现它们令人困惑,所以我倾向于坚持使用常规合并。)

暂无
暂无

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

相关问题 分别合并到qc和master时合并分支之间的冲突 - Merge conflicts between branches when merging to qc and master separately 当分支中的已删除文件与具有该文件的主文件合并时,为什么Git不显示合并冲突 - Why Git is not showing merge conflicts when a deleted file in branch is merged with master that has that file 将分支变基或合并到合并到 master 中的另一个功能分支上 - Rebase or merge a branch onto another feature branch merged in master 将具有无法解决冲突的不同步功能分支合并到 master - Merge out of sync feature branch with unsolvable conflicts to master 为何合并到母版后应删除要素分支 - why should I delete feature branches when merged to master Git - 功能分支之间的冲突 - 如何避免功能分支包含另一个功能分支中的更改 - Git - conflicts between feature branches - how to avoid a feature branch contains changes in another feature branch 当我们在其他分支中合并一个分支时,则本地分支被合并或远程分支被合并 - when we merge a branch in some other branch, then either local branches are merged or remote branch merged 我们可以合并到主分支但从一个更新的分支“A”并忽略合并到 A 的其他分支吗? - Can we merge into the master branch but from one updated branch "A" and ignore other branches that were merged into A? Git 在合并到功能分支时恢复主恢复提交 - Git revert in master reverting commits when merged into feature branch 为新功能创建分支时,一旦合并到母版中,如何删除? - When creating a branch for a new feature, once merged into master, how to delete?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM