3

I have two branches with the structure:

---(commit 1) ----- (commit 2, refactoring) ----(CONFLICT) 
        \                                      /
         \                                    /
          -----(commit 3, modifying) --------/

In the commit 1 I have a file text.txt:

Part 1:
  line 1
  line 2
  line 3
Part 2:
  line 4
  line 5
  line 6

In commit 2 I extract "part 2" of the text.txt into the part2.txt, so I get:

  • text.txt:

    Part 1:
      line 1
      line 2
      line 3
    
  • part2.txt:

    Part 2:
      line 4
      line 5
      line 6
    

In commit 3 I slightly modify both parts of text.txt:

Part 1:
  line 1
  line 2a
  line 3
Part 2:
  line 4
  line 5b
  line 6

Merging two branches I expect git to be smart enough and put line 2a into text.txt and line 5b into part2.txt. Unfortunately this doesn't happen.

My expectations are based on the fact, that git gui blame part2.txt detects origin of the lines correctly showing text.txt.

My questions are:

  • Why doesn't it work out of the box?
  • Is there some workaround known?
4

1 回答 1

1

我没有看到与您相同的结果git gui blame part2.txt。我在提交 2。git gui blame不显示text.txt。无论如何,回答你的问题:

  • 如果它确实“开箱即用”,您认为在以下情况下会发生什么:在提交 3 中,您已更改line 5line 5b. 同时在提交 2 中,出于某种原因,有人将“第 2 部分”行移动到两个相同的文件中:part2a.txtpart2b.txt. git 现在应该自动将这两个文件都更改haveline 5b吗?

    Git 不会试图做出这些决定——它把它们留给你。

  • 如果git-rerere这种确切的冲突经常发生。否则你需要手动处理。幸运的是,有一个merge.conflictstyle=diff3配置选项可以显示基本提交中的文件内容以及两个冲突的提交。这样可以很容易地看到哪一方改变了什么,以及原来是什么。有关详细信息,请参阅git-merge手册页。

于 2013-05-23T00:52:45.530 回答