1

I need to make changesets 2-5 to be on the red (leftmost) branch instead of blue branch. Got weird results with rebase since 2-5 are "based" on 1 anyways. Do I need to cherry pick? I'm currently using Source Tree.

enter image description here

Commits 2-5 must only appear on blue branch after the pull request. Meaning they have to appear on red branch, be approved and only then merged into blue one.

0

1 Answer 1

3

Then just merge the branch. Git will perform a fast-forward merge (there will be no merge commit created), as there are no commits on the red branch, and the result will be that commits 2 through 5 are "on the red branch" - really, the branch pointer will be moved to point to 5, which seems to be what you're after.

$ git checkout <red branch>
$ git merge <blue branch>

# or

$ git merge <commit id of 5>

RE: Your update

It looks like you want to "move" the commits to the red branch. You cannot do that, that isn't how Git works. You can never "move" commits, you only move branch pointers.

If you want the commits to appear "only" on the red branch, you basically just need to swap the branch pointers. You can do this through a series of git reset --hard's, or merge the blue branch into the red branch as above, and then reset the blue branch to the point before commit 2. You'll have to choose which point that is, since commit 2 is a merge commit. You can probably do well by resetting it to the state of origin/blue-branch.

So, do as above, (merge blue into red) and then...

$ git checkout <blue branch>
$ git reset --hard <commit id of red commit>

# OR

$ git reset --hard <commit id of purple commit>

# OR

$ git reset --hard <origin/blue branch>
6
  • Commits 2-5 must only appear on blue branch after the pull request. Meaning they have to appear on red branch, be approved and only then merged into blue one.
    – Cortlendt
    Commented Jun 4, 2014 at 15:36
  • @Cortlendt They will still be on the blue branch. The red and blue branches will point to the same commit.
    – user229044
    Commented Jun 4, 2014 at 15:37
  • I cannot push the blue branch, only the red one, will it work?
    – Cortlendt
    Commented Jun 4, 2014 at 15:38
  • "If you want the commits to appear "only" on the blue branch" - you mean commits appear "only" on the "red" branch?
    – Cortlendt
    Commented Jun 4, 2014 at 15:42
  • @Cortlendt Yes, fixed
    – user229044
    Commented Jun 4, 2014 at 15:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.