See https://blog.nilbus.com/take-the-pain-out-of-git-conflict-re... and https://stackoverflow.com/q/27417656.
See https://blog.nilbus.com/take-the-pain-out-of-git-conflict-re... and https://stackoverflow.com/q/27417656.
https://git-scm.com/docs/git-push#Documentation/git-push.txt...
Manually reading through merge conflict markers feels very old once you get used to this.
When I'm merging, and things are really messed up due to unrelated things being diffed together, in a situation in which both must survive in the merged result, I do this:
1. Find syntactic boundaries before and after the conflict, in order to delimit an area that is a complete piece of top-level syntax, in which the conflict lies. So that is to say if the conflict is flanked by fragments of syntax, I include them.
2. I make a copy of this entire area, so that I have two consecutive copies of the complete syntactic unit, and therefore two copies of the conflict.
3. Go through the first copy and edit it with a view toward one side of the conflict.
4. Repeat on the second copy, but with a view toward keeping the changes from the other side of the conflict.
Example (manually created):
static void foo(int x)
{
<<<<<<<
return x;
}
static void bar(int y)
{
return y;
=======
return x + 1;
}
static void xyzzy(int z)
{
return z
>>>>>>>
}
WTF? Ah, OK: there is originally a foo(), and one side added bar() and the other xyzzy(). We need both. Ah, and foo was tweaked t o be different.OK, what is the complete syntactic unit? We include everything from the "static void foo" to the closing brace after the >>>>>> and copy it. We include markers:
// COPY A
static void foo(int x)
{
<<<<<<<
return x;
}
static void bar(int y)
{
return y;
=======
return x + 1;
}
static void xyzzy(int z)
{
return z
>>>>>>>
}
// COPY B
static void foo(int x)
{
<<<<<<<
return x;
}
static void bar(int y)
{
return y;
=======
return x;
}
static void xyzzy(int z)
{
return z
>>>>>>>
}
Now we work through COPY A, keeping the <<<<<<< side: // COPY A
static void foo(int x)
{
return x;
}
static void bar(int y)
{
return y;
}
// COPY B
static void foo(int x)
{
<<<<<<<
return x + 1;
}
static void bar(int y)
{
return y;
=======
return x;
}
static void xyzzy(int z)
{
return z
>>>>>>>
}
Then through COPY B, keeping the >>>>>>> side: // COPY A
static void foo(int x)
{
return x;
}
static void bar(int y)
{
return y;
}
// COPY B
static void foo(int x)
{
return x + 1;
}
static void xyzzy(int z)
{
return z
}
Now get rid of the duplicate foo. It looks like we need the one which does "return x + 1": static void foo(int x)
{
return x + 1;
}
static void bar(int y)
{
return y;
}
static void xyzzy(int z)
{
return z
}