0

I have this situation:

X-X-X-X-X-X-K-Y develop
            |-Z-X-X-X-W experimental

I want to bringh the changes made in commit Y from the fist branch to the second and put it before the first commit in the second, Z I want then this:

X-X-X-X-X-X-K-Y develop
              |-Z-X-X-X-W experimental

How can I do?

2 Answers2

2

This is the canonical situation where one would use rebase:

$ git checkout experimental
$ git rebase develop
EricSchaefer
  • 25,272
  • 21
  • 67
  • 103
1

first you have to cherry-pick Y to experimental.

Presuming you are on experimental branch: git cherry-pick Y

Then experimental looks like this:

Z-X-X-X-W-Y

Then you have to reorder the commits with git rebase -i Y^ experimental
That will bring up the interactive mode of git rebase. Look at this answer for more information.

The commands you have to use in the interactive mode look like this:

pick Y
pick Z
pick X
# all Xs
pick W

Check the man page of git-cherry-pick, so you get it rigth. And backup your repo before ;-)

Community
  • 1
  • 1
toydarian
  • 4,246
  • 5
  • 23
  • 35
  • Can you explain me the differences with the reply of @EricSchaefer? Because I tried its answer and it works for me perfectly! I'm asking just to learn something more :) – user3807511 Jul 06 '14 at 14:37
  • Its a lot more complicated ;) – I thought, Y would be added to the "end" of the branch, but that was a mistake. Erics way is the best one. – toydarian Jul 06 '14 at 14:45