Merging with Git without a loss of sanity

Share unrelated electronics stuff, ideas, rants, etc!
Post Reply
User avatar
Jubatian
Posts: 1561
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

Merging with Git without a loss of sanity

Post by Jubatian »

Before other topics would receive too much unrelated content...

So how to merge with Git in a clean and sane way, and what to pay attention to? For now just up to debates...

My thoughts.

First and foremost when someone's idea he is working on falls behind the master branch he contributes to, he should be doing the merge with the current state himself. If he forgets or isn't aware of the problem yet, he should be asked to do so. In Github, when opening a pull request, one will see the problem anyway.

The reason in this is that who created a set of changes is who knows the best how they work and which parts of the code do they affect. So he is who can devise best how to merge it nice and clean without breaking anything.

When merging, if Git notifies no problems, that is, a clean merge, in most cases things should be all fine. Compiling and testing features introduced both by your changes and those happened on the main branch is recommended though since there could exist some unlikely edge cases when even then the merge results in broken code (such as for example if one as a part of his changes deleted a function entirely, but the other on completely unrelated places used it, obviously the merge will perform clean, yet the result wouldn't even compile proper).

A merge conflict arising notifies that the two changesets clearly contradict each other in some manner (and this, that a conflict happens when the changes contradict each other, can be expected most of the time). This case the problem might not only lay at the place of the detected conflict, but spread in other parts, so who merges should revise all his changes relating to the conflicting feature whether they sit well with the rest of the code, and fix properly where they don't as a part of the merge commit. Opening the source file merged against and the source file containing the changes to be merged in can help in this process.
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Merging with Git without a loss of sanity

Post by Artcfox »

That sounds like good advice. It also seems to matter from which end the merge is approached. Merging a lot of changes into something, or doing the merge "backwards" and merging a small number of changes into a pre-existing set of larger changes.

As an example, your change touched a lot of files and parts of the code, so when I tried to do the merge I had to look at a lot more code than when you pulled just a few changes that had happened on the branch into your stuff.

I'm still curious which merge tools everyone is using. I used to just use a text editor to remove the conflict markers by hand, but for a large number of conflicts that gets tedious. Now I usually perform the merge with meld, which has on its left pane the local version, the center pane has the "intended result" version, and the right pane has the remote version. Keyboard shortcuts move through the changes, and allow you to select the right or left versions of a section.
User avatar
Jubatian
Posts: 1561
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

Re: Merging with Git without a loss of sanity

Post by Jubatian »

Text editor (mcedit), removing the conflict markers by hand :) But essentially the setup for complex situations is the same you describe with meld: I have three terminals open side-by-side with mcedit showing the respective versions.
Post Reply