I recently encountered a really puzzling problem with Git when merging 2 branch. The problem arose when the auto-merge tried to merge 2 files that contents "mostly" whitespace insert INSIDE a line. For exemple, look at this file after a git merge (or git rebase) :
<<<<<<< f03b9ee0db23cbe39ff231d8fcc3b37bac20cc3d¬
1 public static function findTopParent($tid, $domaine_tree) {¬
2 =======¬
3 public static function findTopParent($tid,$domaine_tree) {¬
4 >>>>>>> Version 8 - last extraction¬
(Notice the space after $tid,) The purpose of this "light" edit was only to play nice with Drupal coding convention (asking to leave a whitespace after coma in function parameters).
I should add that this was one case where merge left revision mark. But there's many cases where the auto-merge does is work without errors but do an awful job at merging files with a chunk of code on top (without space inside) and a chunk of code below (with space)
But having running my usual git merge without much warning or errors, my site stop to work with all kind of function redefinitions errors. Opening the files, I saw chunks of code get repeated all over the place, original code above and the "new" code with whitespaced coma in functions below. So what the hell????? How come simple modification like this is interpreted by Git like a new line or even worse new chunks of code??
I maded thoses changes all over the place for a couples of days and now I having a really bad time re-merging with my main branch. And now, I'm kind of scared to do this kind of "small" change to my files in fear of creating bizarre bugs hiding in replicating code. I check git merge doc but only find whitespace problems related to space at end of line, beginning of line (instead of tabs) or whitespace use for tabbing (core.whitespace). But nothing about problem with space added INSIDE. :-( Need some fresh eyes on this!
EDIT:
To be clear and easier to understand here one extract from a real file, before and after.
In master before the merge:
// Menu Link MLID des pages HUB (statiques) du main-menu
// Requête BD : SELECT * FROM menu_links where plid = 999
// 726 = Loi et Réglements
// 728 = Aide financière de dernier recours
define ('LOI_AIDE_PAGE_MLID',934);
define ('REGLEMENT_PAGE_MLID',935);
define ('AFDR_PAGE_MLID',894);
// Taxonomy VID
define ('DOMAINE_VID',3);
In feature before merge (notice the added space after coma):
// Menu Link MLID des pages HUB (statiques) du main-menu
// Requête BD : SELECT * FROM menu_links where plid = 999
// 726 = Loi et Réglements
// 728 = Aide financière de dernier recours
define ('LOI_AIDE_PAGE_MLID', 934);
define ('REGLEMENT_PAGE_MLID', 935);
define ('AFDR_PAGE_MLID', 894);
// Taxonomy VID
define ('DOMAINE_VID', 3);
Then, on feature branch:
git commit "blablabla"
git pull --rebase origin master (no message, everythings look cool)
git checkout master
git merge feature (fast-forward, no message)
...
run the site... error duplicate constant !?!?
open files and now this!?!
// Menu Link MLID des pages HUB (statiques) du main-menu
// Requête BD : SELECT * FROM menu_links where plid = 999
// 726 = Loi et Réglements
// 728 = Aide financière de dernier recours
define ('LOI_AIDE_PAGE_MLID',934);
define ('REGLEMENT_PAGE_MLID',935);
define ('AFDR_PAGE_MLID',894);
// Taxonomy VID
define ('DOMAINE_VID',3);
// Menu Link MLID des pages HUB (statiques) du main-menu
// Requête BD : SELECT * FROM menu_links where plid = 999
// 726 = Loi et Réglements
// 728 = Aide financière de dernier recours
define ('LOI_AIDE_PAGE_MLID', 934);
define ('REGLEMENT_PAGE_MLID', 935);
define ('AFDR_PAGE_MLID', 894);
// Taxonomy VID
define ('DOMAINE_VID', 3);
And also found file with revision mark but the change is also only ONE whitespace difference.