Git: False Merge Conflicts?

I have been using git for several years, and every time you do a merge, git reports some strange conflicts. Here is an example .htaccess file from which I merged into the new Drupal 7.24 kernel version:

# Protect files and directories from prying eyes. <FilesMatch "\.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)(~|\.sw[op]|\.bak|\.orig|\.save)?$|^(\..*|Entries.*|Repository|Root|Tag|Template)$|^#.*#$|\.php(~|\.sw[op]|\.bak|\.orig\.save)$"> <<<<<<< HEAD Order allow,deny </FilesMatch> # Hide important scripts from malicious users. <FilesMatch "^(autoinstall\.php|install\.php|update\.php)$"> ======= >>>>>>> 7.24 Order allow,deny </FilesMatch> 

How is the conflict here? This is not even a potential case of differences in spaces / ends: in section 7.24 of the conflict there is simply nothing .

Why is git complaining about this? I probably misunderstand something fundamental ...

+6
source share
3 answers

You cannot see the conflict, looking only from two sides. Conflict occurs when both sides make different changes from a common ancestor.

The fact that there is β€œnothing” on the one hand does not matter - there is something in the ancestor, and both sides have changed it.

You can get more conflict data by specifying the ancestor in the conflict files; you can install:

 git config merge.conflictstyle diff3 

Which will show you all three sides of the conflict.

+1
source

Git selects a common ancestor for its associations:

 0 |_________ | | ab |_____|_ | M 

If git detects that both a and b are changes from 0 , this leads to a merge problem that prevents the automatic creation of the merged file M

Have you looked at it in the corresponding tripartite merge tool like p4merge ? This can help show you that git believes that it is a common ancestor and that it perceives it as conflicting changes.

0
source

Theres a worthy explanation of what is likely to happen to your fictitious conflicts here: Case of Cross-Cross Merge (2005-04-28)

 A |\ | \ | \ | \ | \ | \ | \ B8 C3 |\ /| | \ / | | \ / | | X | | / \ | | / \ | |/ \| D8 E3 \ | \ | \ | \ | \ | \ | \| ? 

[...]

The problem is that there is no single ancestor for a tripartite merger that does the right thing.

By the way, this post was written by Bram Cohen, one of the authors of BitTorrent. He later tried to develop his own alternative to Git , which he hoped would manage with these problems. His analysis of the problem is occurring, but I do not think he could ever solve it. There are interesting reasons why this is probably unresolvable, but the StackOverflow post is not suitable for this rabbit hole.

0
source

Source: https://habr.com/ru/post/958591/


All Articles