Git change branch origin (rebase)

f'I have the following:

A---B---C-----D-- branch dev \--C'-E-/ branch test 

I did it poorly: C and C 'are almost the same commits, it would be more reasonable if I could run a branch test on C instead of B.

How can I do this ?, I think rebase, but I'm not sure how to use it, thanks

edit : it was not clear what I would like:

 A---B---C-----D-- branch dev \-E-/ branch test 

or

A - B - D - E - D, if this is not possible

+8
git branch rebase
source share
2 answers

You can overload it on top of a temporary branch (made from C )
See git rebase and rebasing , plus git branch .

 git branch tmp C git checkout test # rebase the current branch (test) on top of tmp git rebase tmp git branch -d tmp 

This should give you:

 A---B---C-----D-- branch dev \--C''-E'-/ branch test 

I left C '(here as C' '), because C' is not exactly the same as C.
But as ams comments, if you need C 'go, you would

 git rebase -i tmp 

This will give you an interactive reboot allowing you to completely remove C' , playing only E on top of C

+8
source share

You can reinstall only the piece you want in C:

 A---B---C-----D-- branch dev \ C'-E-- branch test # git rebase --onto [new base] [starting after this commit] [ending at this commit] git rebase --onto CC' E A---B---C-----D-- branch dev \ E-- branch test 

This is the same concept as selecting a cherry, except for the pointer to the test branch, moves along with the reinstalled commits.

(Note that C 'commit will not be available after rebase, but you can return to it using git reflog .)

+6
source share

All Articles