3

Let's asssume I've got commits

COMMIT_1 COMMIT_2 in my master branch. I've made checkout from COMMIT_2 to create new branch bugFix1 but then I realized that I can't merge COMMIT_2 changes with main repository yet because they are not approved.

So how to move my branch to previous COMMIT_1 without affecting my changes in bugFix1 branch? I don't want to have COMMIT_2 changes either.

Sorry for my bad illustrator's skills enter image description here

lapots
  • 12,553
  • 32
  • 121
  • 242

1 Answers1

2

If you have:

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

You can do a:

git checkout bugfix1
git rebase --onto c1 master bugfix1

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

You can see another example of rebase --onto in:

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250