5 ms·
> I still never groked the use of rebase. Why not just merge the changes together? Is it just "I want fewer total commits in my history" [...]? No, AIUI it's m
by CRConrad 5y ago
> I still never groked the use of rebase. Why not just merge the changes together? Is it just "I want fewer total commits in my history" [...]?
No, AIUI it's more about keeping logically related commits closer together. And also avoiding or minimizing merge conflicts, if you remember to rebase your feature branch back onto master/main periodically before merging it back in.
(Half expecting a run-in with Cunningham's Law here.)
- HWR_14 5y agoThe second example still seems strange - couldn't you just merge the master onto the feature branch to bring it up to date? I also totally don't get the "closer together" comment. It seems like you are reducing the related commits from 2 to 1, not moving any commits closer together. But maybe I'm just quite confused.
- CRConrad 5y ago> couldn't you just merge the master onto the feature branch to bring it up to date? > I also totally don't get the "closer together" comment. It seems like you are reducing the related commits from 2 to 1, not moving any commits closer together. They're related: I meant for the case where you don't (or only lightly) squash your history, so you get several commits from your branch. Maybe if you do regular merges, they're all jumbled up chronologically with whatever else has been merged into master/main in the mean time? Whereas re-base makes it seem that everything in your branch has come "on top of" whatever the current state of m/m is. So when you then later merge your branch back in, all your (possibly compressed into somewhat fewer) commits come as a neat little chain of their own, not interspersed with others? As I said, I may be wrong as fuck here. Feels intuitively right, but intuition often leads us wrong with software (and other logic), especially such famously non-intuitive stuff as git... But that whole thing of "re-base puts all commits in your branch 'on top of' the branch you base(d?) it on" is how I've understood all descriptions of the "rebase" command I've seen. And it's the only way I can make sense of the whole idea -- because otherwise, as you say, it would be the ssame thing as ordinary merges back-and-forth; no need for a separate name for the same thing. (So if you're going to squash the history of your branch down to a single commit anyway, maybe it makes no difference [except possibly for where in the chronological order it goes]? But don't quote me on that either.)
- CRConrad 5y agoFWIW, it seems this[1] (from[2]) confirms my intuition. HTH! [1]: https://www.cloudsavvyit.com/852/what-is-git-rebase-and-how-is-it-different-than-merging/ https://www.cloudsavvyit.com/852/what-is-git-rebase-and-how-... [2]: https://news.ycombinator.com/item?id=24699804 https://news.ycombinator.com/item?id=24699804