[hibernate-dev] Minimizing merge hell
Emmanuel Bernard
emmanuel at hibernate.org
Fri Mar 11 13:15:07 EST 2011
We (as in not me for once) are having a bad experience with massive amounts of merge conflicts. Git is great but there is only so much magic can get you at.
We were discussing how to limit these kind of bad experiences in IRC and I've added a few more advices I could think of.
Try to separate your stylistic / cosmetic fixes from your actual feature commits. They are not related to the feature, they make code review harder, they make some merges conflicts instead of autoresolving.
Even better, try to place them before your feature commits in your commit history. You can do that by doing an interactive rebase and shuffle lines around:
- work on some feature, commit (or stash)
- fix style and commit
- interactive rebase (git rebase -i HEAD~4 assuming 4 is how much commits you want to go back to)
- shuffle the line so that your style commit happens before the other ones
You can even decide to apply your stylistic changes to master even if your feature is still in the work: that will minimize conflicts if people work on related areas in parallel as these cahnges will come quicker.
The general idea is to minimize the amount of possible conflicts in a given commit. Squashing is a great tool but if your commit is 300 files big and has a lot of potential conflicts, you will make enemies both during the code review and during the merge process if it happens to conflict.
For example, I rarely rename a file AND apply changes to it int he same commit, I tend to split those operations.
I'm not sure how merge react to conflicts but with rebase, since every commit is replayed one by one and stops upon conflict, it's more manageable to fix them if they are small and to the point.
Use and abuse interactive adding ie the ability to commit some of your changes. With interactive adding, you can put in the staging area a few line change out of a file changed in multiple areas and commit only that bit. This works great for the stylistic changes we talked about before. The doc for interactive adding is here http://book.git-scm.com/4_interactive_adding.html
Unfortunately the tool is command line based. GitX has a great UI to do that, so if you are lucky to be on a Mac, go and use it. I don't know if other Linux or Windows tool have that feature.
Disable auto import / style fixing features in your IDE.
At least make sure not to pollute commits with these kind of changes just because you've added a line somewhere in the file. Split these in dedicated commits.
I personally run import and style fixes manually from time to time when it makes sense.
Hope that helps
Emmanuel
More information about the hibernate-dev
mailing list