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

Re: Q: rebasing (moving) a whole tree (not just one branch)

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Mar 18, 2011, 21:34 UTC
Message-ID
<20110318213417.GB23407@elie>
In-Reply-To
<7vaagsw2qb.fsf@alter.siamese.dyndns.org>
Junio C Hamano wrote:
>> Dirk Süsserott wrote:
Show 10 quoted lines
>>> I'd like to rebase a whole tree from A to B. Not just a single
>>> branch, but a whole tree. Let's say I have the following history:
>>>
>>> --- A --- B
>>>     |
>>>     + -- C -- D
>>>          |
>>>          + E -- F
>>> 
>>> I'd like to rebase C and its descendants from A to B
[...]
> I am not a huge fan of filter-branch, but shouldn't you be able to
> filter-branch D and F (and no other branch) on top of B?
Yes, something like
	git filter-branch \
		--commit-filter '
			if test "$GIT_COMMIT" = '"$(git rev-parse A^{commit})"'
			then
				git rev-parse B^{commit}
			else
				git_commit_non_empty_tree "$@"
			fi
		' \
		--index-filter '
			if test -n "$(git rev-list -1 "$GIT_COMMIT"..A)"
			then
				# descends from A
				git merge-recursive A -- "$GIT_COMMIT" B
			fi
		' -- --all --not A^

might do it, assuming the diff from A to B is simple enough for a fully automatic rebase.

But in practice, something may well be much better. It depends why we are performing this mass-rebasing --- do A and B have the same content in the moment and different histories? How did the topics we are rebasing get tangled, and is their history going to remain meaningful after this operation?

Jonathan
Previous: Junio C HamanoNext: Johannes Sixt
Message 4 of 5 in “Q: rebasing (moving) a whole tree (not just one branch)”
  1. Dirk SüsserottMar 18, 2011
  2. Jonathan NiederMar 18, 2011
  3. Junio C HamanoMar 18, 2011
  4. Jonathan NiederMar 18, 2011
  5. Johannes SixtMar 18, 2011

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.