Merge and Rebase

Piazza @724


This is a rewrite of an answer I wrote for Piazza @724. A plain text version is reproduced here (with typos reproduced verbatim).

Unsurprising Predicament

Another day of cs400 submit causing mayhem with its reckless git pull --no-edit, creating ugly commit histories *with* its already heinous commit messages.

Git makes branching cheap, but that does not mean branching is always the good idea -- or even make it the right one, so to speak.

Two strategies for combining diverging histories, labeled old for upstream history and new for local history. On the left, the rebase strategy is employed to replay the new commits on top of the old ones; the combined history is clean and linear. On the left, the merge strategy is employed to create a merge commit, one whose parent points to both HEAD of local history and HEAD of remote history.

Merge

The ugly right half of the diagram above.

Rebase

The based left half of the diagram above. (Pun intended.)

Scope of this discussion

Note that I am not talking about merge/rebase workflow in a *collaborative* environment; that opens a whole wormhole of problems, ones that are oftentimes overwhelmingly social. I only focus on Git when used by one person.