threads / discuss / 26779

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

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

## tl;dr

5 messages between Mar 18, 2011 and Mar 18, 2011.

replies: 4people: 4as markdown or json

Dirk Süsserott· Mar 18, 2011, 20:05 UTC · lore
Hi,

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 so it becomes:
--- A --- B
           |
           + -- C' -- D'
                |
                + E' -- F'
I know I can do it manually with

git rebase B C git rebase C D git rebase C E git rebase E F

Is there a way to just say "rebase C and all after that from A to B"?
Dirk
Jonathan Nieder· Mar 18, 2011, 20:26 UTC · re: Dirk Süsserott · lore

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

Hi Dirk,
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'd suggest cheating by making a merge of D and F and "rebase -p"-ing that. :)

To say something more sensible would probably require more information about the particular application, though.

Hope that helps, Jonathan

Junio C Hamano· Mar 18, 2011, 21:14 UTC · re: Jonathan Nieder · lore

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

Jonathan Nieder <jrnieder@gmail.com> writes:
Show 18 quoted lines
> Dirk Süsserott wrote:
>
>> 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'd suggest cheating by making a merge of D and F and "rebase -p"-ing
> that. :)
>
> To say something more sensible would probably require more information
> about the particular application, though.

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?

Jonathan Nieder· Mar 18, 2011, 21:34 UTC · re: Junio C Hamano · lore

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

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
Johannes Sixt· Mar 18, 2011, 22:53 UTC · re: Junio C Hamano · lore

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

On Freitag, 18. März 2011, Junio C Hamano wrote:
Show 21 quoted lines
> Jonathan Nieder <jrnieder@gmail.com> writes:
> > Dirk Süsserott wrote:
> >> 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'd suggest cheating by making a merge of D and F and "rebase -p"-ing
> > that. :)
> >
> > To say something more sensible would probably require more information
> > about the particular application, though.
>
> 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?

Not in a trival way. You would need a tree-filter that re-applies the change between A and B to every transcribed commit. That will work well only if there are no conflicts.

-- Hannes

← back to recent threads