3

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?

amo
  • 315
  • 4
  • 14
  • 1
    possible duplicate of [How can I move recent commit(s) to a new branch with git?](http://stackoverflow.com/questions/1628563/how-can-i-move-recent-commits-to-a-new-branch-with-git) – Rufinus May 24 '14 at 17:57
  • Have you already pushed to origin? If so, you won't be able to achieve this with force-pushing, which will make the rest of your team sad. In which case, you should just `git revert B` on `master`. – Oliver Charlesworth May 24 '14 at 18:01
  • @OliCharlesworth Yes, the commit was pushed to origin. I've updated the question. – amo May 24 '14 at 18:13

1 Answers1

3

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
Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680