Moving commits from one branch to another
I've committed a bunch of changes onto the master branch of my git repository, and pushed it upstream (although I'm the only one working out of these.) What I want to do is to pull these last few commits off, roll back master to before the pulled-off commits, re-apply the commits onto the develop branch, and then merge back onto master.
Here's what my repository looks like now:
a [master] [remotes/origin/master]
|
b
|
c
|
d (merge branch 'develop')
|\
| \
| e [develop] [remotes/origin/develop]
| |
q f
| |
r g
And here's what I want it to look like:
Z [master] [remotes/origin/master]
|\
| \
| A
| |
| B
| |
d C
|\ |
| \|
| e [develop] [remotes/开发者_开发技巧origin/develop]
| |
q f
| |
r g
Can I get some help on this? I'm thinking this is a job for rebase, but I'm not quite sure how to make it happen.
Here you are:
# move cba onto e
git branch foo
git rebase --onto <SHA1-e> <SHA1-d> foo
# rewind master to d
git checkout master
git reset --hard <SHA1-d>
# merge
git merge foo
You might want to pick a more descriptive branch name than foo, since it'll be recorded in the merge commit message for Z.
精彩评论