Git: revert (or rebase -i) a bad commit out of production

We have been using GitHub flow as the basis for our small development teams branching & merging off master. Master was being pushed to staging (for review) and then production. One non-approved feature got stuck on staging while a hotfix, so to speak, branched off of master and as such included the as-yet-unapproved code on staging and got pushed to production. Since then a few more commits have come in on top of that ‘bad’ commit.

We see the need for another shared branch we can use for staging instead of assuming we could share master, but it’s too late hence this question.

I’d like to revert that “bad” commit but not sure the best way to do it. There’s a lot of talk on here and elsewhere about ways to do this but because this is in production I want to make sure I understand the ramifications completely.

Pseudo git log of master branch:

* 2ebe3b7 2014-10-20 | merge a new_feature (HEAD, new_feature, master)
* 4483c83 2014-10-20 | add second feature (second_feature)
* 602bd9d 2014-10-20 | add premature feature (premature_feature)
* c341b06 2014-10-20 | add fileB
* b7ffb78 2014-10-20 | initial commit

I can either:

  1. git revert 602bd9d
  2. git rebase -i c341b06 and rewrite my history without the offending 602bd9d commit.

I don’t have much history “rewriting history” because it’s so taboo to push rewritten history to a shared Git repo.

There are collaborators and origin/master contains the premature code. What’s the cleanest & safest way to get that single commit off of master (and thus out of production)? Looking for any advice/pitfalls.


  • How to make 2.0 branch (started from scratch) master branch in Git. Single Developer
  • Set master branch to latest tag
  • What is the difference between Branch and Remote in GIT?
  • How to fix git after double reset
  • Am having trouble in git push heroku master am getting the error below
  • Git: move a branch to make it point to another
  • How to work with current working copy when moving to old branch in GIT?
  • Vapor: git push heroku master is failing
  • One Solution collect form web for “Git: revert (or rebase -i) a bad commit out of production”

    Just revert the commit. There is a reason why pushing rewritten history to a shared repo is “taboo”; in that case you have to make sure everybody who has ever used the repo does a git fetch followed by a git reset --hard origin/master. The only time one should push rewrites to the server is when one needs to, e.g. when confidential information was accidentally committed.

    Git Baby is a git and github fan, let's start git clone.