Tree surgery

19
Tree Surgery James Aylett

Transcript of Tree surgery

Tree SurgeryJames Aylett

Rebase

“Forward-port local commits to the updated upstream head”

ie: copy part of the tree somewhere else

because of gc, usually deletes the old copy

hence: tree surgery

Possible rebase uses

Update a topic branch

Move into a topic branch

Move out of a topic branch

Mid-limb excision

Possible rebase uses

Update a topic branch

Move into a topic branch

Move out of a topic branch

Mid-limb excision

Update a topic branch

you need more recent commits to continue (eg someone fixed a bug)

“rebase to master”

yours won’t be a long-lived branch (otherwise you’d just merge master back into your branch)

Update a topic branch

$ git rebase master

Possible rebase uses

Update a topic branch

Move into a topic branch

Move out of a topic branch

Mid-limb excision

Move into a topic branch

you need more recent commits to continue (eg someone fixed a bug)

but they haven’t yet finished, so they haven’t merged to master themselves

Move into a topic branch

$ git rebase their-branch

Move into a topic branch

If you need to drop some earlier part of your work

$ git rebase --onto their-branch your-branch~1 your-branch

Move into a topic branch

If you specify a branch to work on (very last argument) git will check that out first:

$ git rebase master their-branch

Possible rebase uses

Update a topic branch

Move into a topic branch

Move out of a topic branch

Mid-limb excision

Move out of a topic branch

you forked off another story

that story has now been merged

you want to rebase rather than merge again (for some reason)

Move out of a topic branch

$ git rebase --onto master branchpoint your-branch

Move out of a topic branch

What if you don’t know branchpoint?

git can (try to) figure that out for you

git rebase --onto master --fork-point their-branch your-branch

Possible rebase uses

Update a topic branch

Move into a topic branch

Move out of a topic branch

Mid-limb excision

Mid-limb excision

You realise some of your commits are pointless and want to get rid of them

You could use interactive rebase (future talk!) to reorder the commits and drop them

However this is more direct

Mid-limb excision

$ git rebase --onto james~4 james~2 james

That’s it!

http://www.slideshare.net/jaylett/tree-surgery

@jaylett