git merge覆盖内容 [英] git merge overwrites contents
问题描述
这是我的情况:
-
我有两个要素分支A&
I have two feature branches A & B.
我想结合这两个分支.
我做了以下事情:
-
创建一个从A分支的新分支C
Create a new branch C branching off from A
签出新分支C
从命令行运行git merge B
我希望两个分支合并.如果对同一文件的更改有冲突,则该命令应引发合并冲突.
I expect both the branches combined. If there are conflicting changes to the same files the command should raise a merge conflict.
但是实际上,在分支A和B中存在一个具有不同内容的同一个文件,但是没有报告合并冲突.而是,分支A中文件的内容被分支B中文件的内容覆盖.
But in actual, there is a same file which has different contents in branches A and B but there was no merge conflict reported. Instead, the contents of the file from branch A are overwritten by the contents of the file from branch B.
我不知道为什么没有报告合并冲突,更担心为什么文件的内容被覆盖.
I have no clue why there was not a merge conflict reported and am more worried why the contents of the file was overwritten.
任何提示或指针都会有所帮助.谢谢.
Any hints or pointers would help. Thanks.
推荐答案
让我们列出发生的事情.
Let's lay out what happened.
- 我有两个要素分支A& B.
- I have two feature branches A & B.
通常是这样的.
4 - 5 [A]
/
1 - 2 - 3 - 6 [master]
\
7 - 8 [B]
A和B分支出master
.他们分歧了.
A and B are branched off master
. They diverge.
但是您可能已经拥有了.
But you may have had this.
6 - 7 [B]
/
4 - 5 [A]
/
1 - 2 - 3 - 6 [master]
这里B从A分支出来.B共享A的所有提交.让我们假设一下.
Here B is branched from A. B shares all of A's commits. Let's assume that.
- 创建一个从A分支出来的新分支C
- Create a new branch C branching off from A
在Git中创建新分支只会在与A相同的提交时创建一个新标签.
Creating a new branch in Git just makes a new label at the same commit as A.
6 - 7 [B]
/
4 - 5 [A][C]
/
1 - 2 - 3 - 6 [master]
- 签出新分支C
- 从命令行运行
git merge B
- Checkout the new branch C
- run
git merge B
from command line
发生这种情况时,Git注意到C是B的祖先.因此它执行快进",这意味着它不会为合并而烦恼,它只是将C推进到B所在的位置.
When this happens Git notices that C is an ancestor of B. So it does a "fast-forward" meaning it doesn't bother with a merge, it just advances C to where B is.
6 - 7 [B][C]
/
4 - 5 [A]
/
1 - 2 - 3 - 6 [master]
如果A和B更改了相同的文件,则似乎B覆盖了A中的更改.
If A and B changed the same files it would appear that B overwrote the changes in A.
git log
和Github不幸地弄平了您的Git历史记录,给您一个错误的印象,即它是线性的.您可以使用git log --graph --decorate --all
查看存储库的真实结构,并在此处检查其是否符合方案.
git log
and Github unfortunately flatten out your Git history giving you a false impression that it's linear. You can see the true structure of your repository with git log --graph --decorate --all
and check if it matches the scenario here.
这篇关于git merge覆盖内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!