Re: Why conflict when merge a branch that the directory is unmodified

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Apr 20, 2024 at 11:00:45AM +0800, wuzhouhui14 wrote:

> Suppose I have two branches with following commit histories:
> 
> B----C---D(directory abc/ modified)               Branch1
>     /
> L--M---O(directory abc/ not modified)            Branch2
> 
> In previous graph, the Branch1 merge Branch2 in commit C. After commit C,
> the Branch1 modified some contents in director abc/. Branch2 doesn't
> modify directory abc/ since commit M, which has been merged into Branch1.
> 
> Then, when I do:
> 
>   git checkout Branch1
>   git merge Branch2
> 
> the director abc/ contains conflicts, why? Because the director abc/ doesn't
> changed since commit M in Branch2, so directory abc/ should not have
> conflicts.

There should not be any conflict (and FWIW I've just verified there is not
using a simple test repository).

I can suggest three reasons (while probably there could be more):

 - The contents of abc has been changed in M; in other words, abc as recorded
   in M is different from its state in C.

 - The files in abc as recorded in D and O have difference in line endings -
   such as on one branch they have LFs and on the other - CRLFs.

 - The graph in a real repository you're dealing with is more complicated
   than presented in your picture, and there exist commits between
   M and O - and may be between C and D as well - which have changed the
   state of abc, but you just failed to spot these modifications during
   your analysis.

Here's a graph from my sample repository where I tried to model your
situation:

-------------------------------- 8< --------------------------------
$ git log --graph
*   commit 7fc08ef95934a404021b46f46df3250340b5122f
|\  Merge: 2a72a51 2c8ef4f
| | Author: user <user@xxxxxxxx>
| | Date:   Tue Apr 23 10:14:31 2024 +0300
| | 
| |     Merge branch 'branch1' into branch2
| | 
| * commit 2c8ef4f49bf2a9900c009a04943422a66b2987c6 - on branch1
| | Author: user <user@xxxxxxxx>
| | Date:   Tue Apr 23 10:14:16 2024 +0300
| | 
| |     modify bar.txt
| |   
| *   commit 001a394ef8d31785362241ef63ca422dad496b39 - M in your case
| |\  Merge: b072e1e e8af26d
| | | Author: user <user@xxxxxxxx>
| | | Date:   Tue Apr 23 10:13:11 2024 +0300
| | | 
| | |     Merge branch 'branch2' into branch1
| | | 
| * | commit b072e1e86f7db47286bc08a435c71486c0ca4f77 - on branch 1
| | | Author: user <user@xxxxxxxx>
| | | Date:   Tue Apr 23 10:12:58 2024 +0300
| | | 
| | |     add bar.txt
| | | 
* | | commit 2a72a51b2aea87f6ed13013865eb181551eba31f - on branch2, like C
| |/  Author: user <user@xxxxxxxx>
|/|   Date:   Tue Apr 23 10:13:47 2024 +0300
| |   
| |       modify abc/foo.txt again
| | 
* | commit e8af26def1078e0293c46a22db3ad788fd6f38be - on branch2
| | Author: user <user@xxxxxxxx>
| | Date:   Tue Apr 23 10:12:08 2024 +0300
| | 
| |     modify abc/foo.txt
| | 
* | commit c7c0b344e943c9d548447886a50fa618e0c7f107 - branch2 is born
|/  Author: user <user@xxxxxxxx>
|   Date:   Tue Apr 23 10:11:42 2024 +0300
|   
|       add abc/foo.txt
| 
* commit 192905a78af1645603f54751ae7139d1aca22a80
  Author: user <user@xxxxxxxx>
  Date:   Tue Apr 23 10:10:56 2024 +0300
  
      root commit
-------------------------------- 8< --------------------------------





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux