Friday, June 24, 2016

This is for that moment when you complete that feature request, test it in dev and staging configuring all necessary environment components, and then the request is retracted. So now all that beautiful code is dangerously lurking in the staging code base awaiting some innocent coworker to pull and maybe accidentally push it up to production push.

Problem: Feature needs to be removed from code base and on hosted sites

Solution: Remove commits from repositories and force push over code

Note* this was simple in my case because no other commits were made after mine, therefore i only has to walk back and reset the commits. The other scenario will be discussed in a future post.

So check out the branch you need to fix, to see the recent history of commits i used

$ git log

There are lots of stack overflows talking about the right way to undo a commit this is my favorite one as it explains what happens to the pointer in a soft compared to a hard reset. So in order to reset the pointer i used the command

$ git reset --hard HEAD~1

The last step is to push to the repo and live code. In order reset the head to this commit I pushed with the option -f, which will force push over the existing code.$ git push [alias eg. origin] dev -f