Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: false merge conflicts?

Tags:

git

git-merge

I've been using git for a few years, and every once in a while when doing a merge, git reports some bizarre conflicts. Here's an example of an .htaccess file, from when I merged in the new 7.24 release of Drupal core:

# 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 there a conflict here? It's not even a potential case of whitespace/endline differences: there's simply nothing in the 7.24 section of the conflict.

Why is git complaining about this? I'm probably misunderstanding something fundamental...

like image 663
coredumperror Avatar asked Nov 21 '13 19:11

coredumperror


1 Answers

You can’t detemine the conflict looking only at two sides. A conflict occurs when both sides make different changes from the common ancestor.

The fact that there is “nothing” on one side doesn’t matter - there was something in the ancestor, and both sides changed it.

You can get more data about the conflict by showing the ancestor in conflict files; you can set:

git config merge.conflictstyle diff3

Which will show you all three sides of the conflict.

like image 171
Edward Thomson Avatar answered Nov 03 '22 04:11

Edward Thomson