3 ms·
Ok, a question from a darcs guy who recently switched to hg: What are the use cases for rebase and lightweight branching? I really don't understand why I shoul
by yummyfajitas 18y ago
Ok, a question from a darcs guy who recently switched to hg:
What are the use cases for rebase and lightweight branching? I really don't understand why I should prefer rebase to simply pull + merge. Also, is lightweight branching just a performance hack, or is there more to it?
- gecko 18y agoRebasing avoids cluttering up your history, and can help make your patches more useful. Instead of showing a fork in your history, followed by independent development, and then a merge, you instead show your branch applied to the tip of the other branch/repository, as if that had been your intention all along. This can result in more meaningful changesets as well: if a change upstream forces some changes to my new feature's code, it will be more useful for reviewing my feature if I rebase my changes so that they incorporate that slight fix. This is superb when you're keeping a fork of an open-source project, and have a collection of patches you want to keep applying cleanly to the remote software, for example. In my opinion, lightweight branching is mostly just a performance hack--and since Mercurial already did cloning with hard links on a local file system, you've been able to get the same performance benefits since before Mercurial 1.0. I do think it's worth understanding, though, that there's also a UI benefit to making building throwaway branches really easy, and I think it's silly to discount that purely because it's a user experience benefit. That's why I do think that having the bookmarks extension in Mercurial 1.1 will be a very good thing.
- mechanical_fish 18y agoIn git, a use case for rebase that I'm intimately familiar with is interoperability with SVN. You can maintain a branch that's a mirror of an SVN repository, but if you do any merging and then try to check the results into SVN the result is a train wreck. In the somewhat acid words of the git-svn manpage: Running git-merge or git-pull is NOT recommended on a branch you plan to dcommit from. Subversion does not represent merges in any reasonable or useful fashion; so users using Subversion cannot see any merges you've made. Furthermore, if you merge or pull from a git branch that is a mirror of an SVN branch, dcommit may commit to the wrong branch. The proper technique is to make a branch based on your SVN repo, make a bunch of changes on the branch (using svn rebase to keep your development branch in sync with changes on the SVN master branch, and -- god help us -- diff-and-patch if you have to merge in changes from some other git branch; this is your penance for working on an SVN-hosted project), then commit the whole thing back to SVN once you have it in shape. It sucks compared to true-blue git but is still nicer than SVN, because (e.g.) you get things like... ... the other use case for rebase, git-rebase --interactive, a.k.a. "take the last N commits and let me reorder, combine, and edit them however I want." I love this feature. See: http://blog.madism.org/index.php/2007/09/09/138-git-awsome-ness-git-rebase-interactive http://blog.madism.org/index.php/2007/09/09/138-git-awsome-n... For more useful ravings about git's features: http://tomayko.com/writings/the-thing-about-git http://tomayko.com/writings/the-thing-about-git
- gecko 18y agoI'm not going to try to sell you on Mercurial vs. git, mostly because I think that argument is pointless, but just so you're aware, Mercurial also supports reordering and combining patches via mq. And that's an area where I personally feel that Mercurial's method actually makes more sense than git's, though you're welcome to disagree. [Edit: Oh, and: yes, that's a perfect example of where rebasing makes sense, and is exactly the kind of rebase operation Mercurial now fully supports, without any complicated patch wrangling.]