Git revert last commit in heroku
I made acommit and pushed it to origin and heroku
Then I realised i开发者_如何学编程t was wrong, so I did
git reset --soft HEAD^
But when I'm pushing to Heroku Im getting
To git@heroku.com:app.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@heroku.com:app.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
I understand the problem. How should I proceed? How can I revert also last heroku commit? (I assume would be the best solution)
If you've reverted the commit locally you may need to git push
with a -f
option to force the commit in.
Also, you may want to have a look at Heroku releases which may help too.
From http://devcenter.heroku.com/articles/releases#rollback
Use the rollback command to roll back to the last release:
$ heroku rollback
Rolled back to v51
You may choose to specify another release to target:
$ heroku rollback v40
Rolled back to v40
Given that you have already pushed to other (public?) repositories, the best way to fix this is probably to undo the git reset
locally, then do a git revert
to create a new commit that reverses the effects of the bad commit. Then push everything again. So step by step:
So first
git reset --hard origin/master
orgit reset --hard heroku/master
(or whatever your heroku tracking branch is called), in order to get your localmaster
back the bad commit. This will blow away any outstanding changes in your working copy, so be careful.Then
git revert HEAD
to create a new commit (it will prompt you for a commit message).Then push as you usually would.
Here's what I did. First, I created a new branch with the old commit:
git checkout -b old-rev <commit-id>
Then I ran push -f
the old branch on the local repo to heroku's master:
git push -f heroku old-rev:master
When I'm done with the old version and ready to get to the new version:
git checkout master
git push heroku master
git branch -d old-rev # deletes the old branch; warns if there will be data loss
精彩评论