Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is wrong with merge commits?

Tags:

I see a lot of questions where people are asking how that can avoid "pointless" merge commits.

What exactly is bad about a merge commit? I find them useful, as you can see exactly where two developers started working, and where there work is merged together. It seems like rebasing, as a lot of answers suggest doing, destroys this information and you lose a lot of the project's history.

Is there something I am missing that makes a merge commit undesirable?

like image 347
Cameron Ball Avatar asked Nov 26 '13 07:11

Cameron Ball


People also ask

Are merge commits good?

Some people keep a merge commit, even for a fast forward, because it keeps a very good record of when a branch was completed. These people prefer "complete and accurate" history over a "clean" history. Some people avoid merge commits, even rebasing their branches, because it keeps the history easier to read.

Why are merge commits good?

Their advantages are not insignificant: you know when a feature got merged in master, its much easier to revert a feature if you have a merge commit for it, much easier to generate a change log with merge commits, and you have none of the problems that pushing "cleaned up" histories will have: https://www.mail-archive. ...

How do I fix incorrect merge?

In your case it should suffice to either: merge again the correct branch with your missing changes. revert the merge commit (and only the merge commit) and then merge the current branch that should have been merged in the first place.


1 Answers

There are two different kind of merge commits:

  • Explicit merge commits, which result for example from explicitly merging a feature branch into the main branch
  • and implicit merge commits, which result for example by doing a git pull before trying to push

The explicit merge commits are usually perfectly fine. You usually even enforce those kind of merge commits by saying git merge --no-ff.

The implicit ones tent to be just noise, as the typical situation is, that one developer changed one file and afterwards another developer works on another file but forgot to pull before doing the changes, and a git pull will implicitly merge both commits by creating a noisy merge commit. The more logical history would be simply one commit from the one author and one commit from the other author. Doing git pull --rebase will exactly do that.

Of course there are exceptions. If both authors actually worked on the same file, it might be better to have a merge commit at this point. - But even in this case maybe a rebase might be better, as it makes the changes against the first commit more explicit and therefore less error-prone.

like image 118
michas Avatar answered Oct 07 '22 21:10

michas