Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Both <code>rebase</code> (and <code>cherry-pick</code>) and <code>merge</code> have their advantages and disadvantages. I argue for <code>merge</code> here, but it's worth understanding both. (Look here for an alternate, well-argued <a href="https://stackoverflow.com/questions/457927/git-workflow-and-rebase-vs-merge-questions">answer</a> enumerating cases where <code>rebase</code> is preferred.)</p> <p><code>merge</code> is preferred over <code>cherry-pick</code> and <code>rebase</code> for a couple of reasons.</p> <ol> <li><em>Robustness</em>. The SHA1 identifier of a commit identifies it not just in and of itself but also <em>in relation to</em> all other commits that precede it. This offers you a guarantee that the state of the repository at a given SHA1 is identical across all clones. There is (in theory) no chance that someone has done what looks like the same change but is actually corrupting or hijacking your repository. You can cherry-pick in individual changes and they are likely the same, but you have no guarantee. (As a minor secondary issue the new cherry-picked commits will take up extra space if someone else cherry-picks in the same commit again, as they will both be present in the history even if your working copies end up being identical.)</li> <li><em>Ease of use</em>. People tend to understand the <code>merge</code> workflow fairly easily. <code>rebase</code> tends to be considered more advanced. It's best to understand both, but people who do not want to be experts in version control (which in my experience has included many colleagues who are damn good at what they do, but don't want to spend the extra time) have an easier time just merging.</li> </ol> <p>Even with a merge-heavy workflow <code>rebase</code> and <code>cherry-pick</code> are still useful for particular cases:</p> <ol> <li>One downside to <code>merge</code> is cluttered history. <code>rebase</code> prevents a long series of commits from being scattered about in your history, as they would be if you periodically merged in others' changes. That is in fact its main purpose as I use it. What you want to be <em>very</em> careful of, is never to <code>rebase</code> code that you have shared with other repositories. Once a commit is <code>push</code>ed someone else might have committed on top of it, and rebasing will at best cause the kind of duplication discussed above. At worst you can end up with a very confused repository and subtle errors it will take you a long time to ferret out.</li> <li><code>cherry-pick</code> is useful for sampling out a small subset of changes from a topic branch you've basically decided to discard, but realized there are a couple of useful pieces on.</li> </ol> <p>As for preferring merging many changes over one: it's just a lot simpler. It can get very tedious to do merges of individual changesets once you start having a lot of them. The merge resolution in git (and in Mercurial, and in Bazaar) is very very good. You won't run into major problems merging even long branches most of the time. I generally merge everything all at once and only <em>if</em> I get a large number of conflicts do I back up and re-run the merge piecemeal. Even then I do it in large chunks. As a very real example I had a colleague who had 3 months worth of changes to merge, and got some 9000 conflicts in 250000 line code-base. What we did to fix is do the merge one month's worth at a time: conflicts do not build up linearly, and doing it in pieces results in <em>far</em> fewer than 9000 conflicts. It was still a lot of work, but not as much as trying to do it one commit at a time.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload