"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 ?
"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 ?
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.
git
itself won't produce that result. It will produce a version with conflict markers (i.e.: <<<<<< HEAD\n [code from head]\n ======\n [code from branch]\n >>>>>> branch
, and it won't commit. It is then up to the programmer to manually solve the conflict. If they do so without introducing new code, then it's not evil. So chaos's last example would not be an evil merge without the --$baz;
line. That would be a stupid merge, but the fault would lie with the programmer, not with git.
Jul 3, 2012 at 3:36
In the words of Linus Torvalds himself (taken from the git mailing list):
an "evil merge" is something that makes changes that came from neither side and aren't actually resolving a conflict
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
").
It is worth to mention that an "evil change" from an "evil merge" can be lost silently while rebasing an "evil merge" containing an "evil change" which does not conflict with other commits.
Using --preserve-merges
does not help in such a case.
git's evil merge
: evil merge is not some natural phenomenon that sometimes happens; Rather, it is something people will sometimes do in git (just like people sometimes cause other accidents like pushing --forced changes to a public repo). The takeaway here is: don't do that! (or at least preserve merge semantics)--rebase-merges
feature), the special actions you took when you made the evil merge—or the special actions someone else took when they made it— will not be repeated automatically and the merge result will differ. The merge will have lost its "evil-ness", in other words. That could be another reason to call it "evil", especially if the result was good / important.