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

5 messages from 2011-03-18 to 2011-03-18. Participants: Dirk Süsserott, Jonathan Nieder, Junio C Hamano, Johannes Sixt.
Thread: https://gitlist.dev/t/26779

## Dirk Süsserott, 2011-03-18 20:05

Subject: Q: rebasing (moving) a whole tree (not just one branch)
Message-ID: <4D83BB0A.8070307@dirk.my1.cc>
URL: https://gitlist.dev/e/4D83BB0A.8070307%40dirk.my1.cc

```
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, 2011-03-18 20:26

Subject: Re: Q: rebasing (moving) a whole tree (not just one branch)
Message-ID: <20110318202637.GA23255@elie>
URL: https://gitlist.dev/e/20110318202637.GA23255%40elie
In-Reply-To: <4D83BB0A.8070307@dirk.my1.cc>

```
Hi Dirk,

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.

Hope that helps,
Jonathan

```

## Junio C Hamano, 2011-03-18 21:14

Subject: Re: Q: rebasing (moving) a whole tree (not just one branch)
Message-ID: <7vaagsw2qb.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vaagsw2qb.fsf%40alter.siamese.dyndns.org
In-Reply-To: <20110318202637.GA23255@elie>

```
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?

```

## Jonathan Nieder, 2011-03-18 21:34

Subject: Re: Q: rebasing (moving) a whole tree (not just one branch)
Message-ID: <20110318213417.GB23407@elie>
URL: https://gitlist.dev/e/20110318213417.GB23407%40elie
In-Reply-To: <7vaagsw2qb.fsf@alter.siamese.dyndns.org>

```
Junio C Hamano wrote:
>> 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 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, 2011-03-18 22:53

Subject: Re: Q: rebasing (moving) a whole tree (not just one branch)
Message-ID: <201103182353.24517.j6t@kdbg.org>
URL: https://gitlist.dev/e/201103182353.24517.j6t%40kdbg.org
In-Reply-To: <7vaagsw2qb.fsf@alter.siamese.dyndns.org>

```
On Freitag, 18. März 2011, Junio C Hamano wrote:
> 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

```
