4 ms·
As an experienced developer and a git noob, this article makes much more sense to me than the plea to use rebase all the time.
by dsjoerg 13y ago
As an experienced developer and a git noob, this article makes much more sense to me than the plea to use rebase all the time.
- jvzr 13y agoDitto. Well explained and all. Eventhough I've used Git for quite some time (GUI are for the lazy, and I'm a lazy basterd) but I still don't understand a damn thing. Well I've grasped the broad concept, but everything smaller eludes me. This post is very well written.
- npsimons 13y agoRebase is a powerful tool, and with great power comes great responsibility. It's easy to get stuff wrong with rebase, and it's also hard for most developers to get their heads around because it offers something that no other VCS does. I'm also very much reminded of http://tomayko.com/writings/the-thing-about-git http://tomayko.com/writings/the-thing-about-git, except to extend it even further, most VCS will tell you "you should have not committed broken code or written a bad message" or "you should have cleaned up your patch before committing it." Git, on the other hand, is extremely forgiving. I've lost count of the number of times I've gone off the rails and deleted a branch name or some other pointer to a commit in git, yet I could always pull it out (even if I had to resort to reflog). But enough about my shortcomings; why should you rebase? I can think of two very good reasons to rebase: to cleanup a patchset before submitting it to a "central" repo, and to move your patch forward on top of another patch set (avoiding a merge). Often times, you might be working on something and get distracted, so you stash or commit and come back to it later. For whatever reason, you may have multiple commits that are conceptually related, but are separate. With git, it doesn't matter if these commits are one right after the other, or separated by other commits. You can rebase them into one commit that makes conceptual sense. If one commit reverts part (or all) of a previous commit, once you rebase and squash them together, the change and reversion cancel out so you don't get unnecessary twiddling of code in your commits. The other time to rebase (that the article argues against doing all the time, which may have some merit), is when another repo you are pulling from has newer changes. So you've got your nifty new cleaned up commit, now you want to push it. But what's this? You can't push it because someone else beat you to it! No worries, you'll just merge. Hold on to that thought though: what's really happening here? Well, you want to put your changes on top of the changes from the repo you pulled from (and hopefully double check that they still build and the tests still finish successfully). Should this operation necessarily be called a "merge"? What if you just pretended that your commit had been based on the new stuff in the remote repo all along? That "pretending" can be accomplished with a rebase, and it also has the nice benefit of keeping your history clear of content-free "merging" messages. So, when should you not use rebase? Never on a public repo that others have pulled from. Even if you are exposing your own repo as a master and warn people that things could change radically at any time, it's still probably best if you clone a personal/private repo off that, do your rebases there, then push clean commits to the public repo.
- joeblau 13y agoYeah I agree. I've been using git for a few years and I think his logic is more sound than the original plea.