Look at the following example:
git log --all --oneline --graph
* fc89735 (HEAD -> master) Merge branch 'feature'
|\
| * 034f1de (feature) modify the calculate function
| * 57aaea2 added another calculation function
* | 382de62 just add a comment
|/
* 303a4ed initial commit
Here is what I did:
1. Initial commit (feature.php) (303a4ed):
<?php
function calculate($a) {
return ($a + 500) * 0.4 + 10;
}
2. I've created a branch FEATURE where I just added another function, a feature... (57aaea2):
<?php
function calculate($a) {
return ($a + 500) * 0.4 + 10;
}
function anotherCaluclation($b) {
return ($b - 500) * 0.2 + 5;
}
3. I've modified the calculation in the calculate function to fit the requirements of the FEATURE (034f1de):
<?php
function calculate($a) {
$a += 1243028;
return ($a + 500) * 0.4 + 10;
}
function anotherCaluclation($b) {
return ($b - 500) * 0.2 + 5;
}
4. In MASTER I've added a comment to the calculate function (382de62)
<?php
//a crazy calculation function calculate($a) {
return ($a + 500) * 0.4 + 10;
}
5. The Feature is finished and I want to intergate it. At this time MASTER and FEATURE have diverged, a fast-forward merge is impossible. In FEATURE the calculation was heavily modified which is correct for the branch, but incorrect for the rest of the project, including MASTER.
However, imagine, the problem is unknown and I'm doing a git merge
, merging FEATURE into MASTER (fc89735):
git merge feature
I get the following log:
Auto-merging feature.php
Merge made by the 'recursive' strategy.
feature.php | 5 +++++
1 file changed, 5 insertions(+)
And this is the resulting content:
<?php
//a crazy calculation function
function calculate($a) {
$a += 1243028;
return ($a + 500) * 0.4 + 10;
}
function anotherCaluclation($b) {
return ($b - 500) * 0.2 + 5;
}
As you can see: The added line $a += 1243028;
from the FEATURE branch (which is correct for that branch but not for the rest of the project) was merged into MASTER.
That means, from this moment on there is a bug in the project, introduced by GITs auto-merge.
How do you deal with that sort of problem? What are possible strategies? From this example I'd plead: All automatic merge actions need to be reviewed manually!
Is there a way to force a manual review of all changes when doing a merge?