Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move specific git commit from master to branch

I have a specific commit that was pushed into origin/master but was not ready for prime time. It should have gone into a separate existing feature branch that will eventually be merged into master. How can I pluck the commit out of master and move it into the feature branch?

Here's what I have in the remote branches:

          a     B     c     d
master -  o --- o --- o --- o -->
                   \
newbranch -         - o --- o -->
                      p     q

The errant commit B needs to be moved to newbranch:

          a     c     d
master -  o --- o --- o -->
             \
newbranch -   - o --- o --- o -->
                B     p     q

Is this possible to achieve?

like image 376
amo Avatar asked Nov 23 '25 10:11

amo


1 Answers

If you have already pushed the commit, then any attempt to rewrite the existing graph will require a force-push, which will make other members of your team sad.

Therefore, the best solution is to simply commit a revert to master:

git checkout master
git revert B   # Or whatever the commit hash for B is
like image 69
Oliver Charlesworth Avatar answered Nov 24 '25 22:11

Oliver Charlesworth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!