在合并时,Git只考虑提交的时间戳,而不考虑它属于哪个分支? [英] While merging, does Git only consider the timestamp of a commit rather than which branch it belongs to?

查看:138
本文介绍了在合并时,Git只考虑提交的时间戳,而不考虑它属于哪个分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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中 C / 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>):这两个文件不受合并的约束(没有任何内容适用于 dev ),并且在 master

您可以 创建新快照,并自动创建一个新快照承诺这一点。这被称为合并提交,并且它的特殊之处在于它有多个父代。


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆