简体   繁体   English

Git分支和合并:来自2个分支的修改没有冲突?

[英]Git branch and merge : modifications from 2 branches with no conflict?

I'm puzzled by the git behaviour and i would like to have some explanations. 我对git的行为感到困惑,我想提供一些解释。 Let me explain, i have 2 branches : 让我解释一下,我有2个分支:

  • master
  • my_feature_branch. my_feature_branch。

The workflow : 工作流程:

  • day 0 : i create my_feature_branch from master 第0天:我从主人 那里创建my_feature_branch
  • day +1 : from my_feature_branch : i do a change in the file "feature.java" 第+1天:来自my_feature_branch :我对文件“ feature.java”进行了更改
  • day + 2 : from master i do a change in the file "feature.java" 第2天:从那里,我对文件“ feature.java”进行了更改
  • day + 3 : from my_feature_branch i merge master into my_feature_branch 第3天:从my_feature_branch合并到my_feature_branch

Result : No conflict. 结果:无冲突。 my_feature_branch do not retrieve the changes from master in "feature.java". my_feature_branch不会从“ feature.java”中的主服务器检索更改。 Git considers that "feature.java" from my_feature_branch is all correct. Git认为my_feature_branch中的“ feature.java”都是正确的。

Consequences : The fix did in master is not reported in my_feature_branch. 结果:在my_feature_branch中未报告在master中进行的修复。

in most cases, Git will figure out how to integrate new changes. 在大多数情况下,Git会弄清楚如何整合新的变更。

However, there's a handful of situations where you might have to step in and tell Git what to do. 但是,在少数情况下,您可能必须介入并告诉Git该怎么做。 Most notably, this is when changing the same file. 最值得注意的是,这是在更改同一文件时。 Even in this case, Git will most likely be able to figure it out on its own. 即使在这种情况下,Git也很可能能够自行解决。 But if two people changed the same lines in that same file, or if one person decided to delete it while the other person decided to modify it, Git simply cannot know what is correct. 但是,如果两个人在同一文件中更改了相同的行,或者一个人决定删除它,而另一个人决定修改它,则Git根本不知道什么是正确的。 Git will then mark the file as having a conflict - which you'll have to solve before you can continue your work. 然后,Git会将文件标记为存在冲突-您必须先解决该冲突,然后才能继续工作。

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

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