git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: nicer frontend to get rebased tree?

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Aug 23, 2008, 21:52 UTC
Message-ID
<alpine.LFD.1.10.0808231440530.3363@nehalem.linux-foundation.org>
In-Reply-To
<4d8e3fd30808231404y7293eb56g4fbed5565ab2aa9a@mail.gmail.com>
On Sat, 23 Aug 2008, Paolo Ciarrocchi wrote:
>
> you got nice and detailed answers,  for example you can track a
> rebased tree in your working directory using git pull --rebase.
> What's wrong with that?
No, you really really cannot do that.

If the _tree_ you are tracking is itself rebasing (not just your own tree), then you cannot and absolutely SHOULD NOT use rebase (not directly, and not with "git pull --rebase".

Why?
Let's look at what happens. Let's say that your history looks like
	... -> A -> B -> C -> a -> b -> c

where the upper-case letters are from the tree you track, and the lower-case letters are the commits you added yourself.

Now, let's say that the tree you track gets rebased, and in the process 'B' is removed (because it turns out it was buggy), and A and C get modified. What happens?

You now have
	... -> A -> B -> C -> a -> b -> c     <- your branch
	  \
	    other stuff -> A' -> C'     <- newly rebased branch

(where "other stuff" is whatever the remote branch was rebased on top of) and when you now try to rebase your stuff on top of the newly rebased branch, you are going to end up trying to rebase all the _old_ commits that weren't even yours (ie it's going to try to rebase A, B and C too!)

And that's not what you want! It will potentially not only generate lots of conflicts (because A' and A aren't the same, and C' and C aren't the same), and it will actually re-insert B - which was buggy - before it finally gets to the commits _you_ actually did (a, b and c).

So no, you canno even sanely rebase on top of another persons rebased tree, because the _other_ person threw away his history, and since you remember their _old_ history, it's basically now you who are in charge of it.

What you can do is to basically do
	git fetch nasty-tree
	git rebase C.. --onto nasty-tree

ie you can explicitly _tell_ rebase which commits you want to rebase. Obviously, "git rebase --interactive" can help you do this (ie you can get the whole list and edit out all the crud that you know isn't yours).

But this is why working on top of somebody elses tree that gets rebased is so hard. You lose all the history, because the other person basically threw it away and started over.

Don't get me wrong - it's _possible_ to do. See above about how you can pick-and-choose the parts you decide you want to keep (your "own" stuff).

In fact, we could even do a form of "rebase" that only picks commits that you committed yourself, and call it "git rebase --my-commits nasty-tree", and that would often do the right thing (assuming the source tree only ever rebases its own commits, of course! If it rebases other peoples commits, it's so terminally broken that you should just refuse to work with that tree, and shoot the maintainer)

So we could do more helper functions for this, but the fact is, it's a really broken model. The real fix is to teach people not to rebase.

			Linus
Previous: Paolo CiarrocchiNext: Paolo Ciarrocchi
Message 35 of 42 in “nicer frontend to get rebased tree?”
  1. Andi KleenAug 22, 2008
  2. Linus TorvaldsAug 22, 2008
  3. Andi KleenAug 22, 2008
  4. Linus TorvaldsAug 22, 2008
  5. Paolo CiarrocchiAug 22, 2008
  6. Linus TorvaldsAug 22, 2008
  7. Björn SteinbrinkAug 22, 2008
  8. Paolo CiarrocchiAug 22, 2008
  9. Linus TorvaldsAug 22, 2008
  10. Junio C HamanoAug 22, 2008
  11. Andi KleenAug 23, 2008
  12. Paolo BonziniAug 23, 2008
  13. Andi KleenAug 23, 2008
  14. Paolo BonziniAug 23, 2008
  15. Linus TorvaldsAug 23, 2008
  16. Andi KleenAug 23, 2008
  17. Linus TorvaldsAug 23, 2008
  18. Ingo MolnarAug 25, 2008
  19. Björn SteinbrinkAug 23, 2008
  20. Linus TorvaldsAug 23, 2008
  21. Björn SteinbrinkAug 23, 2008
  22. Documentating branches (was: nicer frontend to get rebased tree?)Marius Vollmer, Aug 23, 2008
  23. Miklos VajnaAug 23, 2008
  24. Marius VollmerAug 23, 2008
  25. Marius VollmerAug 23, 2008
  26. Avery PennarunAug 22, 2008
  27. Andi KleenAug 22, 2008
  28. Paolo CiarrocchiAug 22, 2008
  29. Jakub NarebskiAug 22, 2008
  30. Andi KleenAug 23, 2008
  31. Paolo CiarrocchiAug 23, 2008
  32. Jakub NarebskiAug 23, 2008
  33. Andi KleenAug 23, 2008
  34. Paolo CiarrocchiAug 23, 2008
  35. Linus TorvaldsAug 23, 2008
  36. Paolo CiarrocchiAug 23, 2008
  37. Björn SteinbrinkAug 23, 2008
  38. Junio C HamanoAug 24, 2008
  39. Jakub NarebskiAug 23, 2008
  40. Theodore TsoAug 23, 2008
  41. A proposed solution (Was: nicer frontend to get rebased tree?)Theodore Tso, Aug 23, 2008
  42. Mikael MagnussonAug 22, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.