RudyGems

Matthew Rudy Jacobs
see me swim
Github
see some of my code
Thought Sauce
Hire me in Hong Kong

I forgot to commit to a feature branch!

So I just committed to master

commit b17a1fbe8f5d59c24a1f2bb50c9905f8345263f5a
Author: Jeffrey Giraffe <Jeffrey.T.Giraffe@gmail.com>
Date:   Wed May 18 18:22:22 2011 +0800
  Started work on an exciting new feature.

But I shouldn’t have.

All features should be in a “feature branch”

How do I move my commit onto a different branch?

Luckily I haven’t pushed yet.

So just start my “feature branch” right now.

git checkout -b exciting-new-feature
git push origin exciting-new-feature

Then go back to master, and undo the commit

git checkout master
git reset --hard HEAD~1

Or if there are 3 commits

git reset --hard HEAD~3

Of course, if I’ve already pushed this would be a little more tricky.

I suggest (for verbosity) you shouldn’t try to do anything fancy.

Just revert it

git revert HEAD

and humbly explain why

Revert "Started work on an exciting new feature."

This commit is not ready to be on master yet,
and has been moved onto the branch "exciting-new-feature"

This reverts commit b17a1fbe8f5d59c24a1f2bb50c9905f8345263f5a.

Boom!