4 ms·
Git merge does something pretty awful; it takes multiple changes and turns them into a single patch bomb in the destination branch. What if the branch has 17 c
by kazinator 5y ago
Git merge does something pretty awful; it takes multiple changes and turns them into a single patch bomb in the destination branch.
What if the branch has 17 commits, the 9th of which introduces a regression? Moreover, suppose that the 9th commit of the original branch didn't exhibit the regression; rather, its change had that effect when it was merged into master.
You need all 17 commits, in their rebased versions, on master, so you can search through their history (e.g. with git bisect) and discover that the 9th one broke it.
Rebase is the correct thing: it calculates a new sequence of commits that are individually merged, and retained as separate commits that you can dig through in the new branch.
What's missing is this: the rebase of an entire branch into a new branch should record a second commit parent (for the final commit of the operation), pointing to the final commit of the original branch.
Like this:
X-Y-Z--<< branch
/
-A-B-C-D-E--<< master
rebase it:
X-Y-Z--<< branch
/ \___
/ \
-A-B-C-D-E-X'-Y'-Z'---<< master
where X', Y', Z' are the rebased versions of X, Y, Z.
A regular git rebase is missing that second parent link from Z' to Z. You just get this:
X-Y-Z--<< branch
/
/
-A-B-C-D-E-X'-Y'-Z'---<< master
The only way you can identify that Z' was cherry-picked from Z is by clues in the commit message: identical commit message text, or something like a Gerrit Change-Id.
Possibly, each cherry-picked commit should have the original as its parent:
X-Y-Z--<< branch
/ \_\_\___
/ \ \ \
-A-B-C-D-E-X'-Y'-Z'---<< master
now that is almost like iterating over the branch and doing a commit-by-commit merge.
At first we pretend that the branch is just X, and merge it to get X'. Then we merge Y', and then Z'. We never merge a sequence of two or more commits into one.
If you do that, you have both: nobody can say you're not merging, but you have the effect of a rebase.
A rebase (cherry-pick) is a kid of merge: of one commit (at a time), without recording all the parents.
A case can be made for rebasing commit-at-at-time using merge. (Not for private work, obviously; just already published, permanent history).
The nice thing about rebase is that it doesn't introduce the crufty parentage, which makes it ideal for rearranging unpublished history and then presenting a clutter-free end result.
- preseinger 5y ago> What if the branch has 17 commits, the 9th of which introduces a regression? Moreover, suppose that the 9th commit of the original branch didn't exhibit the regression; rather, its change had that effect when it was merged into master. For some developers, the commit is the cohesive unit of change. For others, the PR as a whole is the cohesive unit of change. I fall into the second group. The ninth commit of my branch is meaningless -- it's only the branch as a whole which can be understood as a single coherent thing. Squash merges reflect and support my methodology.
- Spivak 5y agoI also have found myself in a shop that uses this flow, and don't get me wrong, it works pretty darn well, but it's also just turns PRs/branches into commits and is effectively a single-branch linear workflow with extra steps. It's the closest thing to not using git that exists.
- preseinger 5y ago> it's also just turns PRs/branches into commits and is effectively a single-branch linear workflow Yes! This is ideal.
- w-j-w 5y agoThis is Continuous Integration or Trunk Based development, and it often shows up in surveys as being a very effective tactic.
- hn_throwaway_99 5y ago> It's the closest thing to not using git that exists. Totally disagree, because the whole reason for this is to support multiple developers working simultaneously of the same master branch. That is, sure, master may just be a linear history of commits, but at any specific point in time there may be 10 feature branches off master, each from a different branch point.
- kazinator 5y agoFactually, the commit is the unit of change. (Gitwise-factually, a commit is a snapshot, not a change, but a new snapshot represents a change relative to some other snapshot, like any one of its indicated parents.) Your "methodology" is not rooted in facts. It can be described as wanting every version control to be CVS. Back in the day when those kinds of systems were widely used, the most common complaint from knowledgeable CM people was that there are no change sets: related sets of changes treated as a unit which contains the fine-grained changes, with individual descriptions, references to tickets and so on. If we regard a feature branch as a change set, when you do a squashing merge in git, you're vandalizing the change set; the merge you're doing is only slightly better than "cvs -j from -j to" (merge the delta between from and to onto the working copy). How it's slightly better is that it records the extra parents, for tracking. One of the main improvements in git over things like CVS and Subversion is that you can at least halfway simulate change sets, due to the relative ease of manipulating individual commits and the scripting done around it (like git rebase scripted around cherry-pick).