3 ms·
> There is precisely zero difference in guarantees of things working or building or whatever between you rebasing or merging a branch into master. In fact, fun
by lmm 6y ago
> There is precisely zero difference in guarantees of things working or building or whatever between you rebasing or merging a branch into master. In fact, funnily enough, if you actually do testing/CI correctly, issuing a "git merge feature-branch" command to land things in master will, with high likelihood do a rebase rather than creating a merge commit. This is because you will have pre-merged (or equivalently, as far as testing the right thins is concerned, rebased) master into your feature branch first. Because that's the only way to actually test the right thing (the state of the code as it will be once it lands it master).
The head commit on master is the same, but the state of previous commits from your branch becomes different and untested, and quite possibly broken. And presumably you valued that commit history on your branch, or why keep them at all? If you want master's history to only reflect the sequence of features landing master, squash-merging is a much better way to achieve that than rebasing - it doesn't create a fictional commit history, just the mega-commits you wanted. Future bisects will land you on a mega-commit, but at least you don't have to handle a bunch of non-compiling states on the way there.
- patrec 6y ago> The head commit on master is the same, but the state of previous commits from your branch becomes different and untested, and quite possibly broken. Try to break it down, and you will see that the scenario you're positing doesn't make much sense and your concerns are unfounded: Let's posit the following: 1. We have a feature branch B, with carefully crafted and individually tested commits. 2. We have a minimally working CI setup (which means we always test the code state of the new head of master before landing stuff in master "for real"). On that assumption one of two things can happen when you try to land B whether via rebase or merge: a) CI fails, because changes in master in the meantime make it so your branch now triggers a test failure or merge conflict whereas before it didn't. We can ignore this, scenario, because nothing lands till b) CI passes. So we know the HEAD commit on master is fine. But, you say, whilst I know the individual commits on B are also good (I tested them all) and the merge commit is good (CI!), with rebase I only know the head commit works -- what if the rebasing broke some intermediate commits? But for that to happen, all the following need to be true: 1. You don't didn't use rebase -x (why not, if you carefully test all individual commits on the feature branch?) 2. Your individual commits all work correctly on the feature branch and would pass CI. 3. The sum of your individual commits plus master works correctly and definitely does pass CI. 4. Because of changes in master branch since the common ancestor of present master and B, a) at least one of the commits of B no longer would pass CI when tested, although it does on the branch (not an unlikely scenario so far) AND b) a latter commit on the feature branch miraculously fixes this incompatibility (because we know the HEAD passes). This is not theoretically impossible, but exceedingly unlikely. And, you can easily guard against it happening as described above.
- lmm 6y ago> a) CI fails, because changes in master in the meantime make it so your branch now triggers a test failure or merge conflict whereas before it didn't. We can ignore this, scenario, because nothing lands till No we can't, because what do people do in this scenario? They make a new commit that fixes the tests, but leaves a long chain of previous commits broken. (Also in a big enough codebase with enough collaborators it becomes impractical to require CI to pass against the absolute tip of your shared development branch before merging, because in the time it takes to run CI there will always have been more changes landing in that shared branch). > 1. You don't didn't use rebase -x (why not, if you carefully test all individual commits on the feature branch?) I've never known anyone to actually use -x. Maybe a very dedicated individual could, but there's no way you'd be able to enforce it across a team (unless that team is in the habit of making feature branches that are just a handful of big commits - but in that case you might as well just squash-merge). Pulling changes from master and resolving any conflicts is already a frustrating interruption; making it take 20x longer is a non-starter. People don't carefully test all individual commits, but that's ok. Even the most casual testing will catch when a commit simply doesn't compile, and introducing a compilation error in manual code changes is much less common than introducing a compilation error when pulling changes from master. And in the worst case, an isolated non-compiling commit in history is not too much of a problem to skip when bisecting. The problem only comes when you have a long chain of non-compiling commits - which is exactly what rebasing tends to produce.
- dragonwriter 6y ago> Maybe a very dedicated individual could, but there's no way you'd be able to enforce it across a team Adopt standard workflow tooling that enforces it, like the gitflow tool but for your actual team workflow.
- lmm 6y agoThis is vaporware; meanwhile a merge-based workflow is working fine in many organisations every day.
- patrec 6y ago