9 ms·
The merge vs. rebase debate
- sampo 3y ago> Merge commits have more than one parent, and Git doesn’t automatically know which parent was the trunk, and which parent was the branch you want to un-merge. Yes git knows: The first parent is the trunk.
- keikobadthebad 3y agoAside from the obvious advantages, `git bisect` with rebase-managed trees works to single patch resolution as you would hope. On merge-damaged histories it only traces it to one giant hairball or another, ie, bisect is made useless.
- sampo 3y ago> it only traces it to one giant hairball or another, ie, bisect is made useless The blog post is advocating a "squash, rebase, and merge" flow, which leaves equally giant hairballs.
- cryptonector 3y agoRight, squash-and-rebase is not very good. You want meaningful history. So if you have a feature branch that adds some feature consisting of N sub-features, R refactorings, B bug fixes, then you want N+R+B commits. The commits you squash are the "fixup" commits; all others stay. You also want good commit order. Basically, write your code, commit, then refactor your commits so that you get nice history of all the changes you made as if you were starting from the final state of play (because you are).
- keikobadthebad 3y agoOh... well, for benefit of others since you seem to know well already, there's no need for merge at all if you are just adding patches that have already been rebased to the HEAD of the tree they're going on. They just go on top cleanly and naturally, and all right with the world. Consumers of the branch fast-forward as normal. There's a pure, linear history with no hairballs that people can bisect to patch granularity. Just say no to merge.
- randall 3y agoShout out https://sapling-scm.com/ https://sapling-scm.com/ who makes this workflow even better.
- chrisweekly 3y agoInteresting; first I've heard of Sapling SCM. Any other comments about it?
- Shish2k 3y agoI’ve been using it for a while, primarily to get all the benefits of the mercurial UX while still using github as a backend, but yes it also makes the stacked-diff workflow[0] really nice thanks to features like “absorb” which will smartly amend changes to a branch (eg if your branch contains one commit to add a server and another commit to add a client, you make changes to both files, then run “absorb”, your server changes will be amended to the server commit and client changes are amended to the client commit) :) [0] Rather than a PR containing three commits “Add server” -> “Add client” -> “fix server”, it is encouraged to submit a PR of “Add server (v2)” -> “Add client” (with the original buggy “Add server (v1)” still visible in the code-review tool, so that you can see what changed in v1 vs v2, while what gets merged into the master branch is only the final bug-free v2)
- capitainenemo 3y agoDoes it support phases? If it has phases, absorb, hg grep --diff, hg fa --deleted, and revsets, that would be pretty much all I need :)
- chrisweekly 3y agoThanks! That's helpful.
- StableAlkyne 3y agoRealistically, how much does merging vs rebasing actually matter - do you save days of time over the year, or just a few minutes cumulatively because the commit graph is prettier? I understand that it makes the history "cleaner," but how frequently do you end up bisecting manually searching the repo's commit history? Even on large projects with dozens of feature branches that eventually make it through a dev / main / prod branch, I've never had a problem when merge was the default rule. But maybe we never hit an otherwise common problem.
- aljgz 3y agoStaying consistent matters. Once I joined a new team and my first task was to take care of a large code reformat everyone was afraid of taking over. I had done a similar thing many times, a super easy thing once you know git and are focused. It turned out a terrible experience for a combination for reasons, but one important reason was that the team used merge workflow, I had always done this in rebase. Don't remember the exact details though.
- Apes 3y agoIn practical terms, fixing merge conflicts and running git bisect are a lot more time consuming when you have a lot of merge commits.
- kevingadd 3y agoIt's just plain harder to reason about the history of a branch when there are a bunch of merge commits in it. Even if I'm not using bisect (I rarely do), having the 'git log' be polluted by merges makes it harder for me to fit everything into my head. I also prefer to think about my branches as 'here is a stack of commits on top of a fixed point in time', so having merges in the middle of that flow makes it much harder to reason about that way. Rebasing to choose a new fixed point is much simpler.
- feanaro 3y ago> Even if I'm not using bisect (I rarely do), having the 'git log' be polluted by merges makes it harder for me to fit everything into my head. How and why? Done properly, a merge commit of a PR breach is semantically equivalent to a squashed PR commit, from the perspective of the "trunk"/main/master branch. It is the commit introducing all of the changes of the PR branch into the trunk branch. If you're about to reason about squashed PR commits, you should be able to reason about merge commits. The only difference is that with merge commits you still have the individual commit granularity available, should you be interested in it.
- JoshTriplett 3y agoI'm a big fan of the rebase workflow, but not of squashing. I wrote it as several separate commits for a reason: documenting each step, making each step revertible, separating refactors from from semantic changes, etc. Squashing makes the diffs much more painful, such as by burying an important change in a sea of mechanical ones when they were originally in separate commits. (A workflow that preserves those commits requires actually having useful commits, and obviously if you have PRs with commits like "fix it" and "fix it more" then it might as well get squashed.)
- jmharvey 3y agoI'm a fan of the workflow where the PR gets squashed in the upstream git repo, but the individual commits are preserved in the PR in the code review tool. I feel that Phabricator handles this well.
- easton 3y agoGitHub and Azure DevOps also do that, you just need to know where to look. I don’t mind squashing either, unless I’m being really intentional or rewriting my history my intermediate commits couldn’t be reverted without leaving stuff broken (totally a me problem of course).
- hamburglar 3y agoIntermediate commits being snapshots of “broken” state isn’t a problem at all. When I quit for the day, I commit, broken or not, and pick it up in the morning. I want to be able to drop my laptop in a puddle and still pick up where I left off when I get a new one.
- iimblack 3y agoI think the problem is putting those broken commits into the trunk. Ideally you want to clean up your commits so if you need to revert you don’t accidentally break your build and so reading thru history isn’t awful.
- cj 3y agoOur git workflow: master branch - code currently deployed to production. never used as the base branch except rare hot fixes staging branch - the base branch for all feature branches. On prod deploy, staging is merged to master with a merge commit (probably could (should?) be a rebase) feature branches - always use staging as base branch Most critically: all feature branches are squashed and merged, so that each single commit in master corresponds to a single PR. Makes it easy to revert PR but difficult to cherry pick after squashing. Also keeps the hit history extremely clean and condensed. Not sure if this method will scale, but it’s working well at our company with 6 engineers with 20 or so feature branches open at any given time. Edit: one reason this works for us is we keep feature branches short-lived (ideally at most 2-3 weeks) and staging gets merged to master twice a week (we do a deploy Mondays and Thursdays)
- hermanradtke 3y ago> we keep feature branches short-lived (ideally at most 2-3 weeks) People that do trunk-based development would consider 2-3 weeks as quite long. My definition of short-lived is about 1 day.
- cj 3y agoIn case it matters, we also push in progress code to remote at end of day. (We don’t rely on local branches for in progress work) I’m guessing with a 1 day PR length, you’re mostly pushing finished code ready for peer review.
- Throw10987 3y agoThat seems sane, is there a cohort of engineers pushing for trunk based development?
- siruncledrew 3y agoThat’s the same method as what we use
- _cenw 3y agohow often do you cut production from staging in this "gitflow light"? in my opinion your staging/production parity needs to be really good if you do large iterations in prod, deploying smaller changes constantly will get you little oops moments more often, but you'll be able to fix them immediately since it's clear what caused it, as opposed as 2+ weeks of commits going to prod at once. we had every feature branch create its own little minimal staging environment and started bugging developers to finish up after a week (the staging environment would tear itself down if not told to stay up explicitly via PR labels). and those feature environments went straight into main/production.
- cryptonector 3y agoActual title: Why large companies and fast-moving startups are banning merge commits I love that title.
- BeefDinnerPurge 3y agoIt seems like git itself ought to be able to combine multiple commits into a single ubercommit for the sake of PRs, but allow pulling each of those sub-commits that constituted it in the first place afterwards for debugging and QA purposes. But I guess these 3d party tools achieve that as well.
- sam_bristow 3y agoYou can basically achieve that with a rebase then merge with --no-ff. You can then just bisect etc with "first-parent" to see the big chunks as they're landed.
- dfawcus 3y agoIt does, if you interact at the CLI, where a "PR" concept does not exist. git diff ^initial-commit~1 final-commit However for that to be available after a contribution has been included in the master branch, one has to use merge commits. Otherwise there are no inherent markers as the graph has been flattened in to a linear sequence. One then has to make use of external tools, or commit comment conventions to recreate what was actually done or intended.
- feanaro 3y agoYES. I've been saying that for years. The fact that it doesn't work this way is really pretty braindead.
- danpalmer 3y agoI think at scale, merges are too problematic, however for a long time I worked on a (small) team who took the approach that got history should represent “what you actually did”, and the thought process behind that, rather than the “perfect ideal” of the changes being made. This brings its own benefits, it is often easier to learn from the commits, it’s often easier to review because you have more granular commits and can follow a dev’s thought process. And if you’re doing post-merge review as we did in the early days, you don’t lose that granularity when squashing. A nice bonus was that because there was no rebasing, no one ever really “broke git”, a classic issue for more junior developers. Ultimately the approach didn’t scale beyond ~8 devs/~500k lines/~15 PRs a day, but it was good for a long time. The important thing though is: have a git style guide, make decisions for reasons that matter to your team, and stick to the style guide.
- deleted 3y ago[deleted]
- phkahler 3y agoWe use rebase on solvespace, along with sensible squashing so most commits along master are pretty self contained. You can see the clean history here: https://github.com/solvespace/solvespace/commits/master/ https://github.com/solvespace/solvespace/commits/master/
- dathinab 3y agoa funny but easy to overlooked aspect of rebase+squash+ff-only merge is that it's basically a patch based workflow in disguise (through with some additional metadata during reviews and similar)
- phreeza 3y agoHow do people with workflows that don't do any squashing do code review? To me it always seems the main consideration deciding on commit size is about being considerate of the reviewer. Don't want to harass them with huge commits but also don't want to send barrages of tiny uncontextualized changes.
- icedchai 3y agoGenerally, I look at the diff with the base branch, not individual commits (unless there is a reason to...)
- mostlylurks 3y ago> How do people with workflows that don't do any squashing do code review? Going through the commits one-by-one or just looking at the entire diff both work just fine in most cases. In the former case, the commit messages (even if short one-liners) actually help understand the story of how and why the changes ended up taking the shape they did, so it's usually actually easier than just reading through one big diff. > To me it always seems the main consideration deciding on commit size is about being considerate of the reviewer. Don't want to harass them with huge commits but also don't want to send barrages of tiny uncontextualized changes. Commits should be atomic. Their size is irrelevant to that consideration. An atomic change may be one character, or twenty thousand lines (if those changes constitute an atomic (= singular and indivisible) change). This usually doesn't result in a barrage of tiny changes that are difficult to understand on their own, but even if it did, commit messages, the sequence of commits, the full diff of the MR/PR, as well as the attached information on the issue tracker you use (which you presumably have if you're doing code review) all provide more than enough context.
- cryptonector 3y agoWhen I do code reviews, - first I review the commit list (including commentary), - then I review all the diffs in one go unless it turns out that it's better to use a different approach, in which case I review all the small commits, then all the large commits.
- Spivak 3y agoMy solution to this is "stacked PRs." main <- PR #1 <- PR #2 <- PR #3 <- PR #4 You can review them in order where the diff view in the PR shows chunks of changes logically grouped together and can be commented on/amended separately. Once everyone is satisfied with the patch set #4 is pulled into #3 is pulled into #2 ... and it shows up in main as 4 commits each with an independent PR history attached.
- senderista 3y agoI like to use pure merge commits on my solo projects (where I actually do use feature branches), because I practice good commit hygiene (and clean up sloppy commits with interactive rebase). But for collaborating with others who can't be bothered to practice good commit hygiene, blindly squashing every feature branch before merging is definitely the lesser evil.
- devjam 3y agoI feel the same way. My commits on a PR are always rebased as I go, into one or two or at most three neat changes. Meanwhile (some) others I work with seem to have no problem creating PRs consisting of a dozen or more changes, most of which with messages like “wip”, “typo”, “fix comment” etc.
- zabzonk 3y agois it just me, or do i feel that whatever workflow you are using greatly depends on what kind of product you are developing, and on what language you are using to develop it in? it might be useful if people stated both, here and elsewhere.
- wandernotlost 3y ago> rebasing creates a cleaner, more understandable history & state of the world without the clutter of merge commits "Cleaner", for some definition of "clean". In this case, pretty, not accurate. I just can't understand the draw of rebase based workflows. It seems to be an expression of a preference for aesthetics over accuracy. What is the point of source control, other than to reliably capture what actually happened in history? As soon as you start rewriting that, you compromise the main purpose. Using merge commits preserves what you actually committed. If you ran tests before you committed, rewriting that commit invalidates that testing. If you need to go back and discover where a problem was introduced or what actually happened, with certainty, in a commit history, rebase undermines that, because it retroactively changes your commits. It's like a huge portion of the industry is collectively engaging in a lie, so that our commit histories look prettier.
- azornathogron 3y ago> What is the point of source control, other than to reliably capture what actually happened in history? Unless you're committing every keystroke, you're recording a curated history. You choose when to commit, and by choosing you declare some historical states to be worth keeping and the rest to be merely incidental. I think usually history "rewriting" (eg, rebasing) is much more about curation - choosing which aspects of the history you care to record - than it is about presenting a false record.
- lolinder 3y agoExactly. To analogize to history history: OP wants the version control history to look like a collection of primary sources. Here's the president's daily calendar, there's the letter he received on April 24 from a small child in Wisconsin. In this model, it's up to future code historians to piece it all together into a story. When I go back and look at the git history, I would much rather have had someone do the work of compiling the story for me at the time. Commits are your chance to document what you did for future programmers (including future you). If you insist on them faithfully reflecting every change you made over the course of three days, then future you will have to piece that all back together into a coherent story. Why not take the chance to tell the story now, so that future you can skip all the false starts and failed experiments and just see the code that actually made it into main?
- thriftwy 3y agoTry getting your git bisect working with merge or non-squash workflow. I don't care how the other developers came up with the solution, I want their changeset neatly tagged in the commit with ticket reference.
- feoren 3y agoThe fact that rebase would ever be preferred over merge just shows how bad Git really is under the covers. It's insane that everyone is re-writing their development history to avoid issues with their source control system. There's no reason that should be necessary at all. Manually intervening and re-writing history should be completely antithetical to a good source control system. And squashing should never be preferred by anyone if the tooling was actually any good. For PRs? You should be able to define a group of commits and look at it as a whole, not just operate on a single commit. For clutter? You should be able to "zoom" in and out, or collapse/expand branches in your UI. For disk space? If the size of each commit was O(size of change + small constant), then squishing wouldn't help, because you'd just be cutting out a few bytes per commit -- assuming you're not thrashing back and forth with your changes. The fact that squashing saves so much space just shows how inefficiently Git is storing things. We're all suffering that Mercurial lost the war. Of course, even Mercurial isn't perfect. Why did we stop innovating on source control systems a decade ago?
- brianzelip 3y agoI dunno…leveraging retrospect is often useful.
- deleted 3y ago[deleted]
- MrDarcy 3y agoExtremely useful almost every time. Why wouldn’t we re-write our personal history just before merging into the main permanent history?
- interroboink 3y agoI'm not a proponent of it, but some people would say: including all the messy history is a more honest representation of what actually happened. By that school of thought, a repo should be recording what happened, not what you want to look like happened. I haven't found it to be terribly useful though. IME, it adds noise for future code archeologists. In very rare cases, having the messy long history can be slightly more useful for bisecting to find precisely where bugs were introduced, simply because it's more fine-grained.
- tomasreimers 3y agoAt some point, we decided that proposed changes (patches) should live in source control before they were approved and brought into history. In my view, this is where the problem lives. I don't care about having an immutable record of the history of patches the same way I don't care about having an immutable record of your keystrokes as you produced the change. That's an implementation detail. However, once something is merged into trunk, I want to know what was merged, when it was merged, who merged it, and any people who approved it.
- jacobegold 3y agoThe funny thing is — this is actually different from how OSS (the initial model that Git was built for) worked. Patches are just applied as a single linear commit to the trunk branch. Committing the history of individual work to the source of truth remote was definitely not the intent of merges.
- sampo 3y ago> shifting to a squash-rebase-and-merge workflow. The benefits are clear: rebasing creates a cleaner, more understandable history & state of the world without the clutter of merge commits. Trunk branches remain linear, and branches function as brief, atomic diffs off the trunk. Arguably, you could achieve the same result of a trunk that looks clean and linear, if the tooling just had an option to hide the feature branches, and show you only the merge commits. But you could also keep the possibility of looking inside the old branches and their individual commit messages, if you wanted to.
- mschuster91 3y agoThe problem with rebase IMHO is that it's very hard to grasp and explain on a "how does it work in practice" way, and it's very easy to mess up into a state that permanently loses data, even for seasoned developers. The combination of both makes rebasing completely unusable for teams largely comprised of junior and intermediate developers - your seniors will spend an awful lot of their time helping juniors to revert git rebase fuck-ups, which is why I've seen it banned in quite the few places. We got enough of our own crap to do without having to deal into what exactly the juniors did prior to noticing they've screwed up. IMHO, it's therefore not surprising to see Facebook using rebase - they have money in abundance, they don't care about some senior dev wasting half a day wrangling with basic tooling.
- hardwaregeek 3y agoI’m confused. Is the workflow to rebase branches and squash merge into main? Because that’s what I do at work and it works quite well. You get atomic PR merges so reverts are easy and you get the clean history for a PR so people can in theory review commit by commit. Although if you want to use merge commits in your own branch, I don’t care because it all gets squashed. I don’t fully get using rebase to merge PRs cause then it’s exposing the commits of the PR, when in fact the PR should be considered atomic code changes. But I suppose for workflows where PRs are not considered atomic code changes, rebasing could make sense. Really, what this boils down to is a confusion between commits as a save point and commits as an atomic code change. With my aforementioned process, commits inside a PR are save points, I.e. I need to just save my code before leaving work, while commits on main are atomic code changes (and therefore should correspond to a single pull request). In the rebase-everything approach all commits are atomic code changes, which I find a little too obsessive since you need to make sure your code is always working when you commit or rewrite your history so that is true.
- choppaface 3y agoThe article author appears to weasel-word merge commits and squash-merge together when they are very different things. Squash-merge into main / feature branch is almost equivalent to rebase and is the workflow Github / Gitlab / etc supports well in the UI. The article author might be conflating rebase and squash-merge in order to create clickbait. In particular the author cites lots of “private repos” but gives no evidence because I guess they’re private haha.
- pattycakes 3y agoThis is the strangest debate and it's not really clear from the blog post what the benefit of picking one gets you. Why does it matter what happens on a devs branch? just do a squash and merge when merging a branch to trunk.
- kragen 3y agoi prefer merge over rebase, but they're both pretty okay; merge is safer, but it's rare for rebase to confuse things so badly i can't figure out what went wrong squash merges, by contrast, are a terrible idea. unless for some reason you make commits with comments like 'another change' or 'try again', maybe because your ci system needs a commit to work from. those should be squashed. but squashing a whole branch means that the refactoring work you had to do is mixed into the same commit with the actual functional changes, which makes it much harder to read the commit later. also, obviously, giant commits in your history cripple git bisect
- koolba 3y ago> The most common critique of the rebase workflow can be boiled down to inadequate support from native Git and GitHub. Rebase commands can be intimidating to execute, and recovering previous commit versions often requires unnerving dives into the Git ref-log. Since branches are effectively free, one "trick" is to backup your branch as a new branch (e.g. "git branch -f my-feature-branch-bk") before starting any voodoo^Wrebasing. There's also the tried and true fallback: https://xkcd.com/1597/ https://xkcd.com/1597/ > Even with everything done right, a rebase-centric workflow will flood your GitHub PR timeline with force push events. These force pushes happen even when you've merely rebased your changes onto a newer trunk, leaving the diff unchanged. Yes that's the price you pay for a linear history. For a high churn PR there's no need to rebase on every push, if the PR itself is still in flux and/or you're pushing purely to leverage the centralized CI system, it's fine to tack on additional "wip" commits without rebasing. It's only the final product that must be rebased to get that silky smooth linear commit history. And you should be doing that anyway so that the logical changes in your PR are unified into a single cohesive unit.
- kayson 3y agoI really like the idea of rebasing because it gives you a much easier-to-parse revision history (assuming you enforce good commit messages, structure, etc). The problem I have with it though is early development. The history can be a total mess since lots of things are changing quickly. I often feel like it's not worth the effort of good commit discipline so early on, but once we get to an alpha or beta state, I find myself wishing we had a clean commit history where every commit on main passes CI (which may not have existed in the early commits). Does anyone have suggestions on how to address this? The two easy answers that come to mind are 1) squash everything into an "initial commit" once possible, or 2) just don't worry about old commits passing CI. What I've ended up doing is rewriting the history to move everything on main to a "legacy" branch and have a single merge commit start what ends up being the production version of main. Even with a script, it's still error prone and a little scary to me...
- WesolyKubeczek 3y agoOn a project I worked on, there were a few fans of rebase who liked rebasing long-lived branches on top of trunk a lot. They also used to think that resolving conflicts was very simple and clear-cut. And it had indeed been so simple for them that when they finally merged their work into trunk, several bugfixes that had been released a while before the merge, just disappeared. When the users had reported that some old bugs reappeared, it took me some time to first confirm that I wasn’t going senile and that those bugs had been fixed before, then I couldn’t find the code I had put in, then I recreated some old PRs by hand and reapplied them. I don’t know what went wrong then and who was the idiot, and I think that my life is too short to find out exactly how it may have happened, but no commit has vanished since a blanket ban on rebasing and force-pushing.
- magicloop 3y agoI think that is 2/3 of the story. The other 1/3 is the "patch" workflow. In linux kernel development, it is all about sending patch sequences to a mailing list, comprising well-crafted logical steps. Then the maintainer applies the changes. This side-steps the rewrite merge history problem. This is, I argue, what the default workflow was supposed to be, as the workflow came out of the LKML working practices in developing git. The way I see it from a project scaling perspective, the patch based workflow is the most scaleable. Written another way: patches > rebase > merge I think it also gives the best change history, again patches > rebase > merge Pull Requests were really a GitHub thing. I like them. I wish people made the best out of them. When they do the atomic change to the trunk, it is worthwhile using a hand-crafted meaningful message explaining the goals, and reasons for making the change, together with a terse heading sentence ahead of the detail. Why many people advocate for rebasing for clean history, but leave a trash default-created PR merge commit message has always puzzled me.
- 0xfffafaCrash 3y agoIn my opinion if one could choose between a well executed and instant rebase versus a well executed and instant merge, one would be a fool not to choose a rebase every single time. In practice too, I also almost always choose rebases, BUT there are a few caveats here that are worth making… As a general rule rebases for more than a small number of commits in cases where conflicts are non trivial can take significantly more time and patience for the developer performing it. Instead of fixing the conflicts in one swoop, you have to sometimes resolve conflicts repeatedly in the same areas of code. If the conflicts are extensive this can be a very unpleasant experience even for experienced developers. For less experienced or less skilled developers each of these conflicts poses an opportunity to mess up. Since there are more of them when rebasing, there are also more opportunities to mess up. If the developer is in a rush or is simply impatient, I would also expect them to mess up more in a rebase than a merge. Yes, ideally we wouldn’t have massive branches that need to be rebased with many conflicts, but in practice if you are working on a codebase where a lot is happening frequently by lots of people in the same parts of the code or code is moving around, there are often no really good alternatives. While perhaps more changes can be made incrementally than people often admit (especially if you include feature flags and the like to allow for transitions — though those can come with their own pitfalls), in practicality, not everything can in practice be done without having longer branches (and not having unreasonably large changes in a commit). Sometimes large changes just need to be brought in together. Slow reviews or at least slow code reviews at the same level of effectiveness in the review can pose problems as well. If you want it properly reviewed in the safest possible way you really want no new code in the branch being merged to after the review begins — allowing a clean fast forward merge from the rebased branch, but that can be impractical in some codebases with a lot of activity. Merges can still be messed up and until recently it was quite hard to even see the merge diff to debug a bad merge, but there are admittedly fewer steps where you can mess up. All that said, I’m still a huge advocate of rebasing, but I get it that not everyone is up to the task. Sadly most developers have tons of awful, broken, and incoherent commits on their own branches that they never clean up. Until you can convince them to at least do fixups and cleanup the commit histories on their on branches with rebasing, arguing for rebasing over merges towards trunks is pointless. It requires more from the developer upfront. If your developers are good it will require much less from a maintenance perspective but the reality is that having a team of capable developers who are willing to do the work is not something one can take for granted in most places.
- derriz 3y agoThe fundamental issue with git is that it doesn’t have branches. What git calls a “branch” is a misnomer - it should be called a version/commit pointer. In a tree of versions/commits a single pointer does not identify a "path" through the tree of versions. When talking about VCSs in general, the word “branch” is used to mean a linear sequence or chain of versions connected by a parent/child relationship. Unsurprisingly many git users also have this mental picture of "branches" in git which causes confusion - but it's is not really the fault of users. For example, if the current main/master commit in git has two parents (which it will have after a merge) then it is not possible to know with certainty which of the two parents was previously pointed to by main/master and which came from the feature "branch". Thus git is unable to present a picture/log of the main/master branch as a linear sequence of commits - all it knows about main/master is what it currently points to. So when you log, it has to present the entire tree which means mingling up commits which were master/main commits and which represent work on feature "branches". With other "true" branching VCSs, a branch identifies an actual sequence of commits and is not just a pointer to a single version. Thus you can navigate the history even after merging. You can ask it to only show main/master commits or only show commits created on a specified branch. While once a git "branch" is advanced or points to a new commit/version, the fact that it previously pointed to a specific parent is lost. So git "branches" can only identify a linear sequence of versions if every commit only has a single parent. And this is what the rebasing workflow gives you. And this is why the rebasing workflow, dissatisfying as it is, provides the least friction when using git. If you use merges, then you have commits with multiple parents and now your main/master _pointer_ can no longer be used to identify a single path/sequence of commits. If main/master points to a commit with two parents, git does not record which of the parents came from main/master and which represents work which was, at one time, pointed to by the feature branch. So while I prefer VCSs with true branches so that merge workflows can be supported but I've given up trying to use such workflows with git - it's just not supported in a useful way.
- TrianguloY 3y agoMy rule of thumb is basically: will someone else view (or specially be affected by) the change? Then use merge. Will not? Then use rebase. On a local branch? Definitely rebase. On a branch from an active pr? Definitely merge. Most situations are not so straightforward (what about a pushed branch without a pr? And with a draft?) But in those case mostly depends on the team. If you know/think someone used/reviewed that branch, never rewrite history. Otherwise please do.
- SAI_Peregrinus 3y agoA change should be atomic. Whether the unit of change is a commit or a pull request that gets squashed is irrelevant, what matters is that the resulting history can be understood & bisected, that changes can be reverted, and that changes can be cherry-picked. Work-in-progress changes should be able to be backed up. This doesn't have to happen in the version control system, but it can, and if it does this should not interfere with the goals of atomic changes.
- TrianguloY 3y agoI know it is not possible, and I know it is hard to implement it correctly and working on all cases, but if we could have a "git willRebaseFail" test that just checks if a clean and direct rebase is possible without touching anything, then rebase will be used a lot more. We could even have a git rebaseIfPossibleOrMergeOtherwise and set it as the default...
- TheCleric 3y agoSquashing and rebasing is lying. Don’t lie.