how to finish reverting a commit, and how to revert a lot of commits
Instead of running
git revert --continue
Just run
git commit -m "commit message here"
If that doesn't work, make sure you've staged all the files involved in the revert. Even the files that you reverted and then discarded changes to.
I'm assuming here that no one else interjected commits in between your work, and that you bad commits form a continuous range in the repo's history. Otherwise you're going to have to get more complicated. Let's assume your history looks like this:
e82401b - (master, HEAD) My most recent private commit
...
bc2da37 - My first private commit
cf3a183 - (origin/master) My most recent bad public commit
...
292acf1 - My first bad public commit
82edb2a - The last good public commit
The first thing we want to do is blow away the commits that you haven't made public yet. You can do this with the following command (note that your changes will be gone and should be considered unrecoverable):
git reset --hard cf3a183
Equivalently (and more readable):
git reset--hard origin/master
Now your view of the repository agrees with the view in origin/master
. You now want to revert your bad public changes and publish them as a revert commit. These instructions are for creating a single revert commit.
You can use git revert --no-commit a..b
to revert all the commits starting at the commit after a
(note that!) and ending at, and including, commit b
. The reversion will be staged for you to commit. So, here, we would do:
git revert --no-commit 82edb2a..HEAD
Or, equivalently:
git revert --no-commit 292acf1^..HEAD
Remembering that HEAD
now points to the same place as origin/master
.
After running the revert
command you now have your changes staged and ready to commit, so just run a simple git commit -m "Reverting those bad changes I accidentally pushed and made public"
.