I have two branches off of master, each one for a different feature, and then I have a synthesis branch that combines the two. I committed something to the synthesis branch, but now I see I would have rather applied that change to one of the branches particular to that feature. Is there a way to do this unapply/apply somewhere else maneuver with git?
Make sure you are on the branch to which you have been committing. Use git log to check how many commits you want to roll back. Then undo the commits with git reset HEAD~N where “N” is the number of commits you want to undo. Then create a new branch and check it out in one go and add and commit your changes again.
You can move commits from one branch to another branch if you want changes to be reflected on a different branch than the one to which you pushed the changes.
Cherry-pick commit to target branch and reset source branch. Assuming, you want to move the latest commit from source
branch to target
, do:
git checkout target git cherry-pick source git checkout source git reset --hard source^
If the commit wasn't the last, you will have to use git rebase -i
instead of the last command and choose specific commit name for your cherry-pick
.
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