Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy 1 commit from one branch (dev) to another (stable) with clean working dir

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.

like image 922
Rudie Avatar asked Aug 25 '11 22:08

Rudie


People also ask

How do I merge changes from one branch to another in git?

The "merge" command is used to integrate changes from another branch. The target of this integration (i.e. the branch that receives changes) is always the currently checked out HEAD branch. While Git can perform most integrations automatically, some changes will result in conflicts that have to be solved by the user.

How do I move multiple commits from one branch to another?

You can do this with multiple commits too, just cherry pick several, then reset back to the last commit you want to keep. The process is the same if you have committed to local master by mistake - just cherry-pick to a branch, then reset master. Only ever do this if you haven't pushed the commits to origin.


1 Answers

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
like image 193
Matthew Flaschen Avatar answered Sep 30 '22 14:09

Matthew Flaschen