7 ms·
Linus on git rebase and merge (2009)
- morsch 13y agoOne of his points is that you should only pull rarely: And, in fact, preferably you don't pull my tree at ALL, since nothing in my tree should be relevant to the development work _you_ do. Sometimes you have to (in order to solve some particularly nasty dependency issue), but it should be a very rare and special thing, and you should think very hard about it. That might work well for the kind of highly decoupled development he's dealing with, but I'm not sure it'll work for the kind of work I do with my colleagues. The first thing I do every morning is a git pull (often surrounded by git stash [pop] and sometimes with a --rebase appended if I have outgoing commits), because I might need the stuff a colleague worked on the past days, or we might work in the same files and generate lots of conflicts otherwise. Maybe I'm doing it wrong.
- crististm 13y agoLinus comments is valid in your case: your colleague's work is relevant to you, thus you have a reason to pull. Otherwise, pulling on a time base will give you little benefit besides the occasional breaking of your stuff. If you review now Linus comment, it makes sense that pulling should be done on a feature branch: one that has a complete, working solution of something you need.
- IgorPartola 13y agoAn alternative that worked really well for me is "do not push broken code". Linus is saying "If you pull at a random time, you might get cruft in your local tree". Why is that? There should be no cruft upstream from you. There may be a conflict between your code and remote, but that is up to you to resolve as the remote works and your code does not work with it. His suggestion that in order to keep your git history pristine you should just email patches until you can get to a working state seems bizarre. git is a tool that works really well for collaborating on something until it works. In a small project, who gives a crap if you see a commit that fixes the previous commit once in a blue moon. Yes, on a large project like the Linux kernel that might get annoying, but for 99% of people it's irrelevant.
- dan00 13y ago> An alternative that worked really well for me is "do not push broken code". Linus is saying "If you pull at a random time, you might get cruft in your local tree". Why is that? It's not about pushing broken code, it's about having a very complex code base and you just can't foresee how each change will behave before it has been tested by a lot of people on a lot of different machines. A linux release is a pretty good point in time to get a quite well tested version and therefore it's a good base for your changes and to be able to test how your changes - only your changes - behave.
- IgorPartola 13y agoGood point. However, that still means that this advice does not apply to most people in the wild as most people are not working on projects that large.
- dkarl 13y agoI think his comment is relevant for people who treat their "private" git history very differently from the "public" git history. My "private" git history contains lots of minor commits for stuff like checkpointing, fixing stupid errors, etc. The commit messages sometimes aren't very informative. I clean things up when I reach a good working state, and the history that becomes public is much simpler, with fewer commits and an informative message on each commit. If I share my crappy "private" history with someone else, then I forfeit my ability to clean it up later. That doesn't matter if you keep a pretty clean history in the first place, but I definitely do not.
- saraid216 13y ago> His suggestion that in order to keep your git history pristine you should just email patches until you can get to a working state seems bizarre. To me, it doesn't sound meaningfully different from walking over to a coworker and arguing over the code or its results for a while. The "emailing patches" thing seems more like a slow-by-necessity feedback loop due to the fact that Linux contributors are across the world and even IMing or real-time screen-sharing doesn't make sense.
- Peaker 13y agoContinuous integration, or frequently pulling, has huge advantages: * Breakage is localized to small merges. Instead of debugging the breakage of 1 month of work integrated with yours, you debug it a day of work at a time. Localized/differential debugging is much easier. * Ditto with conflicts. Dealing with daily conflicts is much easier than dealing with the aggregate of a month's conflict. Beyond a certain threshold of difficulty, conflict resolution quality becomes very low. People just give up and start resolving conflicts semi-randomly.
- alexchamberlain 13y agoDo you work on topic branches?
- morsch 13y agoSometimes -- I usually don't pull into those unless strictly necessary.
- alexchamberlain 13y agoI highly recommend a bout where you do everything on topic branches; the advantages will become sell evident over time and then you will know when and when not to use them.
- dan00 13y agoI don't think, that you're doing something particularly wrong, but for a big project like linux you have to keep the changes as isolated as possible, otherwise it will be quite hard to identify the causes, if there're problems. So it's better to base your changes on the commit of a linux release, which has been tested quite a lot, which has some kind of defined state.
- glanotte 13y agoI don't think the point is that you should pull rarely. I think the key there is _my_ tree and he later refers to a branch named linus. I would suspect that he maintains his own development tree that gets pushed to the central repository and then merged to master when he feels it is ready. But prior to it getting merged, it is random and subject to his own rebasing. I have a similar flow, I might maintain multiple feature branches but I will pull and rebase master very regularly to be sure I am working against the most recent code base. I will also rebase my work to squash commits to create a clean history prior to moving work from my feature branches to master. So if someone was to pull in one of my feature branches prior to it being merged or tagged, that tree would very likely change and then we have two versions of my work that would create a merge nightmare when we decided to get everything into master.
- jlarocco 13y agoI don't think he's talking about "git pull" from a central repo, but instead a "git pull <url-to-linus'-private-repo>". But I can also imagine it being useful for everybody to pull the code from the last release and work on it, before a single person pulls the code, merges, and commits it to the central repo.
- dadoes 13y agoYeah, I think you're right. Linus isn't talking about pulling in general, just pulling from his work.
- martius 13y ago(2009) http://news.ycombinator.com/item?id=655005 http://news.ycombinator.com/item?id=655005 http://news.ycombinator.com/item?id=4612331 http://news.ycombinator.com/item?id=4612331
- develop7 13y agoYup, instead of pushing git core devs into adopting at least mercurial "phases" concept or thinking on another way to solve this problem, reposting "do not handle it this way" guidelines is preferred.
- alexchamberlain 13y agoPolite, yet still extremely useful. Is Linus getting old?
- oelmekki 13y agoI'm not sure to understand the point about rebase destroying the history. Does he speak specifically about `git rebase -i` ? I very often run `git rebase master` in my feature branches to avoid having many conflicts to resolve just before my pull request to master. Once merged in master, initial commits I rebased from master did not seem to have changed. Am I missing something, here ?
- Supermighty 13y agoYou're not missing anything. Rebasing off master is the same as a fastforward only merge. It is -i that can actually change the history.
- fr0sty 13y agoRebasing and fast-forward merging are two very different things. whenever you rebase you create _brand new commits_ based off another part of the project history which bear a strong resemblance to the original commits but are nonetheless different. adding -i allows you to do further modification of commit contents (reordering, squashing, dropping, etc. but a vanilla rebase is still changing history. Linus addresses this in his mail early on: "People can (and probably should) rebase their _private_ trees (their own work). That's a _cleanup_. But never other peoples code. That's a "destroy history" "
- Supermighty 13y agoAre you saying when I rebase off of upstream on my private branch does that change the sha1 of the upstream commits? That hasn't been my experience. As far as I can tell. Edit: OK, I did a test and I can see that it is changing the sha1 for my commits on my private branch after I rebase from upstream master. So at least the way I'm doing it I'm not changing public comit hashes.
- aneth4 13y agoThe resulting code may be the same. The resulting repository and history most certainly are not.
- jebblue 13y agoI've been teaching myself git on side projects for several months. I've read through Linux's man page tutorial at least twice, I think I'm starting to get git. It's revolutionary. It will probably still be in use a half-century from now. It's almost too much power, I think some of the git commands should use ASCII art to paint a big picture illustrating the power of the command the user is about to invoke and double checking with the user, do you really want to "xyz", rebase, etc.
- 6ren 13y agoRemember, it's all immutable data structures. So whatever you do locally (i.e. apart from git push), the old version is still there - git reflog will show it. Git eventually garbage collects old versions (i.e. not accessible from a branch), but by default only after a month. Unfortunately... using git reflog to find the old version and undo a command itself has a learning curve. :\
- jordanthoms 13y agoThis for me is the one feature of git that I could never give up. The confidence that, once a state has entered my history, I can always get it back is really helpful when playing with things.
- Peaker 13y agoI doubt git will be used half a century from now: * Heuristic textual diffing is probably inferior to recorded actual diffs from our code editors * Git merges are monolithic, and hide conflict resolution work within them in a difficult-to-review way. On the other hand, git cherry-picks do not track history properly. Future revision control will probably solve this problem better (e.g: darcs seems like it should work better, except darcs has some other [probably more important] disadvantages).
- jheriko 13y agoor just don't use git... :)
- octo_t 13y agoi agree, on my team we manage code by just having project_name_YYMMDD_RELEASE in a big folder /code. Works fine for us! /s
- webwarrior 13y agoI think parent meant using Mercurial or other DVCS that doesn't have such silly thing as "history rewriting". Leave that to politicians :-)
- npsimons 13y agoMercurial will eventually have history re-writing; I say this as an outsider who has watched Mercurial slowly catch up to git by adding features that git has already had for a while. They will have to add it sooner or later to remain relevant and competitive. The article explains why it makes sense to rewrite history - it's so as not to push garbage out on the world. One of the big niceties of distributed, disconnected repositories is that you can muck about, try things out, make mistakes, correct them, clean things up, and then push that out to a public repo. The difference with git is that you don't have to make a separate patch, roll things back (possibly restarting with a clean repo from master), then apply the patch and make a "clean" commit - you simply rebase the commits in git. When I'm maintaining code, I don't care about every little twiddle of bits that happened; I care about discrete, human-level, bug or feature related patches, and sometimes development in progress doesn't match up with that. Being able to rewrite history means being able to have not just maintainable code, but a coherent change history.
- alayne 13y agohg already has a rebase extension http://mercurial.selenic.com/wiki/RebaseExtension http://mercurial.selenic.com/wiki/RebaseExtension
- vadivlkumar 13y agoIt's fun to read Linus writings. It's rude and on the face. Git is exactly him, rude and on the face. Does wonders!
- picomancer 13y agoThe main reason you don't want to rebase published code is to avoid inconveniencing other people. But that doesn't imply that code that's under heavy development and may need rebased should always be hidden from the world and kept totally private. One workflow I've seen other projects use -- that I've also adopted for my own projects -- is to have a separate (non-private) branch called "pu" (pending updates) or "wip" (work in progress). With warnings in the developer docs that this branch may be rebased at any time. In short, keep code that you're willing to rebase clearly delineated from the code you're not, tell other people that it may be rebased in the future, and let them decide whether the benefit of pulling the code today outweighs the drawback of potentially being inconvenienced by a rebase tomorrow.
- tsenkov 13y agoI think this mail is an anthem of the "proper" and paradox-free TimeTravel - "never-ever-ever destroy other people's history". :)
- VladRussian2 13y agoLinus emails archive for software engineering is like Feynman's lectures for QM. Very clear delivery of the right stuff without dumbing down.
- frosas 13y agoHow this applies if I want to share my branch to accept changes from other developers (think pair programming, handovers of half-done features, ...)?