Skip to contentSkip to conversation

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

DISCUSSION Dirk Süsserott 4 participants 5 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw

Hi Dirk,

Quoted 10 lines · Dirk Süsserott

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

#2 lore raw
Quoted 11 lines · Jonathan Nieder
Quoted 9 lines · Dirk Süsserott

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

Quoted 7 lines
Quoted 1 line

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?

#3 lore raw
Quoted 12 lines · Junio C Hamano
Quoted 12 lines
Quoted 10 lines · Dirk Süsserott

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

[...]

Quoted 2 lines

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

#4 lore raw
In reply to Junio C Hamano
Quoted 13 lines · Junio C Hamano
Quoted 12 lines · Jonathan Nieder
Quoted 10 lines · Dirk Süsserott

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

Quoted 8 lines
Quoted 5 lines

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