Move branch from master commit to previous commit

Suppose I have commits

COMMIT_1

COMMIT_2

in my branch master

. I created checkout

from COMMIT_2

to create a new branch bugFix1

, but then realized that I could not merge the changes COMMIT_2

to the main repository yet because they were not approved.

So how do I move my branch to the previous COMMIT_1

one without affecting my changes in the branch bugFix1

? I don't want to have a change COMMIT_2

.

Sorry for my poor illustrator skills enter image description here

+3


source to share


1 answer


If you have:

x--x--c1--c2      (master)
            \ 
             y--y (bugfix1)

      

You can do:



git checkout bugfix1
git rebase --onto c1 master bugfix1

x--x--c1--c2    (master)
        \ 
         y'--y' (bugfix1)

      

You can see another example rebase --onto

in:

+2


source







All Articles