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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With