Git – Does frequent committing prevent merge conflicts

git

Is there any situation, where git merge command uses frequent committing in one or both branches to prevent merge conflict (as opossed to one giant commit of week-long work followed by immidiate merge), or are those things independent?

Best Answer

Making several small commits rather than one big one will not magically prevent conflicts, but it usually makes them less frequent and easier to deal with.

If you commit and push lots of small changes to master, then it's harder for conflicts to arise in the first place, since less code is changing between commits and the other developers will see some of your changes before they start to make their own.

If you have a feature branch that's broken up into lots of small commits when you merge, then the merge is done one commit at a time, so if there are a lot of conflicts, you only have to resolve one commit's worth of conflicts at a time, which is usually a lot easier than resolving them all at once.

The git merge command itself does not perform any commits, except for a single "merge commit" if necessary. It will not retroactively split an existing commit into several smaller commits or anything like that (I don't believe there's an easy way to do that in git, or any other VCS).

Related Topic