简体   繁体   English

Git分支和合并

[英]Git branching and Merging

I have a specific scenario for branching and merging explained below :: 我有一个具体的分支和合并方案,如下所述:

Lets say I have a "Master" branch in a git repo. 可以说我在git repo中有一个“ Master”分支。 And there is a feature branch say "Feature1" taken from master on which approx 200 people will be working. 并且有一个功能分支,称为“ Feature1”,来自母版,大约有200个人将在该分支上工作。 Now I want to take another branch say "Team_Feature" where approx 20 people will be working. 现在,我想再说一个分支“ Team_Feature”,大约有20个人将在这里工作。 Meanwhile I have to keep "Team_Feature" branch in sync with "Feature1 Branch". 同时,我必须使“ Team_Feature”分支与“ Feature1分支”保持同步。 After "Feature1" branch is done, it will be merged to master and New branch "Feature 2" will be taken, During all this time my team will keep working on "Team_Feature", which will be merged with "Feature 2 branch". 完成“ Feature1”分支后,它将合并到master并使用新分支“ Feature 2”。在这段时间内,我的团队将继续致力于“ Team_Feature”,并将其与“ Feature 2分支”合并。

Now, I rebased Feature1 branch into Team_Feature, which I will be doing once every week. 现在,我将Feature1分支重新建立为Team_Feature,我将每周执行一次。

Problems faced :: The second time I rebase, I got many merge conflicts, belonging to different cases mentioned below 面临的问题::我第二次进行基础调整时,我遇到了许多合并冲突,属于以下提到的不同情况

  1. Many conflicts were of type (add/add) 许多冲突属于(添加/添加)类型
  2. Many were (rename/delete) 许多人(重命名/删除)
  3. Many were edit conflict, with the conflicts in the file that never changed in Team_Feature branch. 许多冲突是编辑冲突,而文件冲突在Team_Feature分支中从未改变。
  4. And a few of the conflicts were legitimate ones. 其中一些冲突是合法的。

So, the questions are, 所以问题是

  1. What is this add/add, rename/delete, rename/rename conflicts? 这是什么添加/添加,重命名/删除,重命名/重命名冲突?
  2. What causes these conflicts to trigger? 是什么导致这些冲突触发的?
  3. how to avoid them? 如何避免它们?
  4. The most important doubt is number 3 in above list. 最重要的疑问是上面列表中的第3位。

Please Help, Thanks in advance :) 请帮助,在此先感谢:)

Objectives: 目标:

  1. Keep Feature1 in sync with master and in future merge it to master 使Feature1与母版保持同步,以后再将其合并到母版中
  2. Keep Team Feature in Sync with Feature1 and in in future merge to Feature2 使团队要素与Feature1保持同步,并在将来与Feature2合并

Solution: 解:

  1. Keep merging master to Feature1 on daily basis 每天继续将母版与Feature1合并
  2. Keep merging Feature1 to Team Feature (After above point#1) 继续将Feature1与团队功能合并(在第1点之后)
  3. Once Feature2 comes to existing, keep merging Feature2 to Team Feature on daily basis. Feature2出现后,请每天继续将Feature2与Team Feature合并。

So, the questions are, 所以问题是

What is this add/add, rename/delete, rename/rename conflicts? 这是什么添加/添加,重命名/删除,重命名/重命名冲突?

What causes these conflicts to trigger? 是什么导致这些冲突触发的?

--> There are lot of links to understand this, (rename/delete, rename/rename)basically it is tree level change to a file in both the branches in merge and both changes are different. ->有很多链接可以理解这一点,(重命名/删除,重命名/重命名)基本上是在合并的两个分支中对文件的树级更改,并且两个更改都不相同。 Except add/add -> This is file content level conflict, like adding different contents at same line number in same file 除了添加/添加->这是文件内容级别冲突,例如在同一文件的同一行号添加不同的内容

how to avoid them? 如何避免它们?

  • Avoid working with such complex branching an alternative can be to use toggles instead of feature branching. 避免使用这种复杂的分支,一种替代方法是使用切换而不是功能分支。

  • If you are working in feature branch model, write a mail to complete team about the area you are working on and ask them not to do tree level changes in that area like delete,rename, etc. It is much easier to solve content conflicts but painful to solve tree level conflicts. 如果您正在使用要素分支模型,请写一封信给完整的团队有关正在处理的区域的信息,并要求他们不要在该区域进行树级更改,例如删除,重命名等。解决内容冲突要容易得多,但是解决树级冲突很痛苦。

  • In the end it is not easy to avoid conflicts in big teams which works in branches. 最后,要避免在分支机构工作的大团队中发生冲突并不容易。

I highly recommend using toggle in such cases to avoid complex merge conflicts. 我强烈建议在这种情况下使用切换,以避免复杂的合并冲突。 - Toggle is runtime time condition(flag) for a feature which can make that feature run in two possible way based on the toggle flag. -切换是功能的运行时间条件(标志),它可以基于切换标志以两种可能的方式运行该功能。 All features are worked under toggle in only one branch. 所有功能仅在一个分支中通过切换操作。

Example:- 例:-

Lets say we are implementing a New Details page, 假设我们正在实施“新详细信息”页面,

we will first set up a toggle whose value is stored in some file say new_details_page=true 我们将首先设置一个触发器,其值存储在某个文件中,例如new_details_page = true

Now in code we will have some thing like this if(new_details_page == true) { render 'newPage' }else{ render 'oldPage' } 现在在代码中,我们将拥有如下内容:if(new_details_page == true){render'newPage'} else {render'oldPage'}

If the work for new details page is not complete and you want to release your product with old details page, then simply build the application with that flag as false and deploy to release environment. 如果“新详细信息”页面的工作尚未完成,并且您要发布具有旧详细信息页面的产品,则只需使用该标志为“ false”构建应用程序,然后部署到发布环境。

At the end, the best solution to avoid merge conflicts in this case is to use toggle, you can read more on internet about toggles vs feature branching. 最后,在这种情况下避免合并冲突的最佳解决方案是使用切换,您可以在Internet上阅读有关切换与功能分支的更多信息。

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

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