14

I tried to understand How to undo a commit and commit the changes into the other branch in Git? but I don't think it has to be that hard. (Answer is using branch -f and stash and I don't think I need those.)

I was working in my dev branch. Had two different commits in dirty working dir. Commit all changes in two different commits. Last commit is WIP (so dev material). Second to last is done and should be copied to stable branch.

I imagine something like

$ git copy e87568fa stable

but I'm pretty sure that's not it.

Has cherry picking got something to do with it?

To be sure: I want the commit to stay on dev. So not mv it, but cp it.

I'm still baffled by all these GIT options and commands.

Community
  • 1
  • 1
Rudie
  • 52,220
  • 42
  • 131
  • 173

1 Answers1

21

Go to the stable branch:

git checkout stable

Copy the desired commit to the current branch.

git cherry-pick e87568fa

You can now return to dev:

git checkout dev
Matthew Flaschen
  • 278,309
  • 50
  • 514
  • 539
  • I don't have a dirty working dir. Without the `stash` I just did exactly that (http://stackoverflow.com/questions/1334027/git-working-on-multiple-branches/1340143#1340143). Perfect! Thanks. I might even remember this one =) and most definitely use it again. – Rudie Aug 25 '11 at 22:31
  • I did the steps above, plus another line of : `git cherry-pick {commit-ID}` to move the `{commit-ID}` to the dev branch – AceMark Oct 04 '13 at 12:41