在合并时,Git只考虑提交的时间戳,而不考虑它属于哪个分支? [英] While merging, does Git only consider the timestamp of a commit rather than which branch it belongs to?
问题描述
我在Git中有两个主要分支: master
和 dev
。
结构我的分支机构看起来像这样:
B - > E - > F - > G(主分支)
B→C→D→H→I→J→K(dev分支)
在执行合并之前, master
和 dev
有一个共同的父母 B
。
在提交 E
, F
和 G
master,我删除了一些文件(比如 foo
和 bar
),但它们仍存在于 dev中
/ code>分支。
因此,当我执行三向合并以加入 G
和 K
通过创建提交 L
, L
不再包含foo和bar!我没有以任何方式通知Git他们失踪。
在我看来,因为 E
, F
和 G
在提交 C
之后重播,因此 foo
和 bar
不见了。
Git合并的这种行为对我来说很奇怪。因为我无法知道是否有人从另一个分支中删除了一些文件。
我不应该至少在合并时通知有冲突的修改吗?
不应该至少在合并时通知任何冲突修改吗?
在这种情况下,no:合并 dev
至 master
报告< dev
(自共同祖先 B
)至 master
。 >
这里foo和bar在 dev
之后是未修改,因为 B
。并且他们从 B
中被删除。没有冲突(如果 foo
和 bar
其中未在 dev中修改$ c> $ c>):这两个文件不受合并的约束(没有任何内容适用于
dev
),并且在 master $ c中保持不变$ c $(意为已删除)。
您可以 创建新快照,并自动创建一个新快照承诺这一点。这被称为合并提交,并且它的特殊之处在于它有多个父代。
I have two main branches in Git: master
and dev
.
The structure of my branches look like this:
B-->E-->F-->G (master branch)
B-->C-->D-->H-->I-->J-->K (dev branch)
Before I performed the merge, master
and dev
had a common parent B
.
In commits E
, F
and G
of master, I deleted some files (say foo
and bar
) incorrectly while they still exist in commits C
onwards in dev
branch.
As a result, when I performed a three-way merge to join G
and K
by creating commit L
, L
does not contain foo and bar anymore! And I was not notified by Git in any way about their disappearance.
It seems to me that because E
, F
and G
were simply replayed after commit C
hence foo
and bar
were gone.
This behavior of Git merge is strange to me. Because I would not be able to know if someone deleted some files from another branch.
Shouldn't I be at least notified about any conflicting modifications while merging?
Shouldn't I be at least notified about any conflicting modifications while merging?
In this case, no: merging dev
to master
reports modifications from dev
(since the common ancestor B
) to master
.
Here foo and bar were not modified in dev
since B
. And they were deleted in master since B
. There is no conflict (if foo
and bar
where not modified in dev
): those two files are not concerned by the merge (nothing to apply from dev
), and remains unchanged in master
(meaning deleted).
You can preview a merge with:
git checkout master
git diff --name-status dev
That would list the deleted files.
Can you give me some pointers as to how Git decide which commits to replay during a merge?
Git does not "replay" commits when merging (only when rebasing): it only consider the two branch HEADs (and the common ancestor).
Git creates a new snapshot that results from this three-way merge and automatically creates a new commit that points to it. This is referred to as a merge commit, and is special in that it has more than one parent.
这篇关于在合并时,Git只考虑提交的时间戳,而不考虑它属于哪个分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!