合并分支会修改未在其中修改的文件

时间:2017-11-09 12:57:28

标签: git

好的,所以我有一个我要合并的分支。简而言之,让我们将其重命名为BranchName。

$ git checkout BranchName
Switched to branch 'BranchName'
Your branch is up-to-date with 'gitlab/BranchName'.

现在,我有一个特定的文件。它在这个分支中没有被修改,因为它肯定比6个月大。

$ git lg **/FileName.cs
* ac3b137db - nat traversal 1.53 (6 months ago) <dangodustj>
* 6f32fc2b8 - nat traversal update, stone pickable, junk (9 months ago) <dangodustj>
* 79b8512c9 - nat (11 months ago) <dangodustj>

现在,让我们切换回主人。

$ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'gitlab/master'.

最近在master中修改了这个文件:

$ git lg **/FileName.cs
* 2150fffea - Remove if (Unity5_3) (5 hours ago) <AlexNik>
* 140c9a2e9 - AddLog (5 hours ago) <AlexNik>
* ac3b137db - nat traversal 1.53 (6 months ago) <dangodustj>
* 6f32fc2b8 - nat traversal update, stone pickable, junk (9 months ago) <dangodustj>
* 79b8512c9 - nat (11 months ago) <dangodustj>

因此,当我测试合并时,我希望此文件中没有冲突。

$ git merge --no-commit --no-ff BranchName
Automatic merge went well; stopped before committing as requested

然而,这不是实际发生的事情 - 它将被合并修改!事实上,我对主文件中对此文件所做的更改将被还原。

$ git status
On branch master
Your branch is up-to-date with 'gitlab/master'.
All conflicts fixed but you are still merging.
  (use "git commit" to conclude merge)

Changes to be committed:

        modified:   Assets/NAT Traversal Example/FileName.cs

(编辑合并状态以省略所有其他修改过的文件)。

发生了什么,为什么?

1 个答案:

答案 0 :(得分:2)

原来,原因在于BranchName中发生的错误合并提交。在BranchName中,其中一位开发人员决定合并到主分支。

$ git lg BranchName
*   b3e1488c9 - (HEAD -> BranchName, gitlab/BranchName) Merge branch 'master' into BranchName(7 minutes ago) <Max Yankov>
|\
| *   44b5e21e0 - (gitlab/master, master) Merge branch 'v0.7' (17 minutes ago) <Max Yankov>
| |\
| | * 304622395 - (gitlab/v0.7, v0.7) Changed creature follow constants (77 minutes ago) <Max Yankov>
* | |   ed17d73e3 - MergeWithMaster (29 minutes ago) <StasEremeev>

但是,在处理合并提交时,他删除了除合并冲突解决方案之外的所有修改:

$ git show ed17d73e3
commit ed17d73e32c52b0230010c625c845f50eb47f1e8
Merge: 2e1eec38e 101b691a2
Author: StasEremeev <se.dev@hypetraindigital.com>
Date:   Thu Nov 9 15:35:23 2017 +0300

    MergeWithMaster

diff --cc Assets/Objects/Player/NewWilliam/PlayerACBig.controller
index 91a992a17,d31c43d06..b12458394
--- a/Assets/Objects/Player/NewWilliam/PlayerACBig.controller
+++ b/Assets/Objects/Player/NewWilliam/PlayerACBig.controller
@@@ -115,13 -115,13 +115,13 @@@ AnimatorController
      m_DefaultFloat: 0
      m_DefaultInt: 0
      m_DefaultBool: 0
-     m_Controller: {fileID: 0}
+     m_Controller: {fileID: 9100000}
    - m_Name: Equiped
      m_Type: 1
 -    m_DefaultFloat: 0
 +    m_DefaultFloat: 2
      m_DefaultInt: 0
      m_DefaultBool: 0
-     m_Controller: {fileID: 0}
+     m_Controller: {fileID: 9100000}
    - m_Name: legAngle
      m_Type: 1
      m_DefaultFloat: 0

这是整个提交 - 来自master的所有其他更改都已从合并提交中删除。由于此合并提交具有在FileName中作为其父级更改的所有提交,因此当您尝试将此分支合并回主服务器时,它会有效地覆盖(并撤消)这些更改。

<强>更新

我也见过同样的行为 - 提交空合并提交 - 由我们使用的托管Gitlab提供:

$ git show 428a6d87f
commit 428a6d87fc70bea3a04eff18d7be5665f144102c (HEAD -> master, gitlab/master)
Merge: b7c3bc993 599603a5c
Author: golergka <golergka@gmail.com>
Date:   Thu Nov 16 11:23:22 2017 +0000

    Merge branch 'ChangeAttractorRadius' into 'master'

    Change attractor radius

    See merge request hype-train/wild-eight!274

这是从Gitlab网络界面触发的合并 - 这是整个合并,没有合并任何实际更改。