tags:

views:

213

answers:

3

"man gitglossary" contains this definition of an evil merge:

An evil merge is a merge that introduces changes that do not appear in any parent.

I am not sure I understand the point the authors are trying to get at. Why is it evil ?

A: 

Might be because it appears to be merge but is in fact not.

Sebastian Ganslandt
It is merge (as: it is a merge commit), but it is *evil* merge because it cannot be result of any automatic merge.
Jakub Narębski
Actually, I agree with Sebastian: a merge that breaks the rules about what a *real* merge *is* isn't really a merge at all, is it? The git system might label it a "merge", but it's not a true merge, as meant by the abstract concept of "merge". So, an evil merge is a non-merge in a merge's clothing. So to speak.
Dan Moulding
@Dan, what do you mean by true merge? If you mean something like a fool-proof merge - such a thing doesn't exist IMHO. Is it picking 'ours' or 'theirs'? - no that's not always enough.Keeping both versions? obviously not. Point: sometimes you do need manual edits combining both (see Jakub's reply for examples). I would *not* call those evil (not sure if git guys were thinking about these); only those that contain modifications _not directly need for merge resolution_.
inger
+6  A: 

Because it's putting things in the code that no one ever asked to be there. As if you had this code:

$foo = bar;
$baz = qxx;

and this change:

$foo = bar;
$foo++;
$baz = qxx;

got merged with this change:

$foo = bar;
$foo--;
$baz = qxx;

in a fashion that somehow produced:

$foo = bar;
$foo++;
$foo--;
--$baz;
$baz = qxx;

Clearly, this is evil.

I would guess that it's of enough concern to be in man gitglossary because the more involved your merging algorithms are, the more likely it is that they will produce such a thing.

chaos
To produce this, simply call git-merge with the --no-commit option, add some more changes, check them in, and commit. The pregenerated merge commit message will automatically be used.
Jefromi
@Jefromi By this definition, any merge with a conflict that has to be resolved manually is an evil merge? There is a strong semantic difference to what @chaos says; you could potentially get his results without getting any kind of conflict in the merge process. Which is truly evil.
krosenvold
+4  A: 

I think it might be named 'evil merge' because it is difficult corner case for "git blame" to solve when annotating file (generating line-wise history annotations).


Evil merge migh be needed when you developed feature 'A' on main branch, and feature 'B' on side branch, and those features conflict in semantic (non-textual) way. An example would be using the same name for global variable, with different meanings -- this requires renaming the variable for one of features.

For evil merge "git show --cc" has non-empty compact combined diff (but I am not sure if it is equivalence relation; the implication might be in one direction only, i.e. "evil merge" then non-empty "git diff-tree -p --cc").

Jakub Narębski
Intuitively, @chaos' response feels more correct, but I know that you're good with these things ;) It feels like you're describing a good old merge conflict, where 2 people have solved overlapping parts of the same problem - or maybe even the same problem. Once the merge is finished, why would you want to recreate it? Isn't it overly poetic to call this "fairly regular" incident "evil" ?
krosenvold
Resolving a conflict *usually* involves choosing one of versions over the other, sometimes choosing one version lines over lines from other version. Evil merge has lines which are not in any of its parents, so it cannot be automatically recreated even by a most sophisticated (generic) merge strategy.
Jakub Narębski
*(Removed line about "evil" merge and automated process)*
Jakub Narębski
@Jakub, I think you rightly emphasised 'usually'. Sometimes the _minimal_ manual resolution results in lines that weren't there.(eg. 'ours' changes the name of a function, 'theirs' changes the return value, we need a method with new name and new return val). Is this an evil one? IOW: are evil merges sometimes necessary?+1
inger