3

I have a branch that was built off of another branch, but should actually be a separate branch off of master (they are distinct features). Right now I believe I have this :

...- master
        \  
         A1 - A2
               \
                B1

What I want is for none of the changes in the A branch to be in the B branch. The result should be:

         B1
        /
...-master
         \   
          A1 - A2      

So far I've tried git branch --set-upstream-to=master and git rebase master (while on B) but that's not doing what I want.

  • 2
    You'll need an interactive rebase `git rebase -i` It will allow you to select the commits you want to rebase. Checking out the branch that's currently on `B1` and doing a `git rebase -i master` (and then just selecting `B1` for rebase) should do the trick. – toniedzwiedz May 13 '15 at 21:01

2 Answers2

3

This should be a rebase --onto:

git checkout B1
git rebase --onto master A2 B1
Alex Pan
  • 4,341
  • 8
  • 34
  • 45
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • This looks like the most succinct way to do what I asked for. If I had made more commits to the B branch, would I want to use the latest one (say B3) in the statement or does that mark where the rebase starts? – Michael Winterstein May 13 '15 at 22:07
  • All commits *after* A2 up to the current HEAD (B1, or, after several commits, B3) are rebased onto master – VonC May 13 '15 at 22:17
0

one way may also be to create a new branch from master and cherry-pick the commits done on B1

git checkout master
git checkout -b B1 #(either delete beforehand B1 (git branch -D B1) or use a different name here)
git cherry-pick SHA-Commit-on-B1
...

since cherry-pick supports range of commits, see https://stackoverflow.com/a/3664543/1657377 this may also be worth a try

Community
  • 1
  • 1
jethroo
  • 2,086
  • 2
  • 18
  • 30