So, you've committed some changes to your repository that you want to roll back. This will tell you how to roll that back. It assumes that you want to pretend that the offending commit(s) never happened. Note that this workflow is the simplest solution, and works well for us because we are a small team that communicates well, but it is generally considered bad practice because it rewrites history and can mess up collaborators.
-
Find the commit that you want to roll back to, and copy the SHA (the unique alphanumeric string that identifies the commit).
-
In git bash, type:
git reset --hard theSHA
This rolls back your local copy of the repository to the commit specified by the SHA. If you have not pushed the bad commit(s) to a remote (e.g., GitHub), you can stop here.
-
If you have pushed to a remote, you will need to 'force push' your reversion to the remote, because now it looks like you local repo is behind the origin, and a regular push will be rejected:
git push -f origin branchname
-
Let your collaborators know that you've done this, because you have now rewritten history, and it will affect them if they had previously pulled down the commits you've just reverted. They won't be able to do a regular pull, they will have to reset their local copy to mirror the origin: First make sure you are on the proper branch:
git checkout branchname
Then fetch the remote and hard reset your branch to the state of the branch that was just force-pushed:
git fetch --all git reset --hard origin/branchname
http://willi.am/blog/2014/08/12/the-dark-side-of-the-force-push/
http://stackoverflow.com/questions/927358/how-do-you-undo-the-last-commit
http://stackoverflow.com/questions/9813816/git-pull-after-forced-update