Git revert last commit in heroku

GitHeroku

Git Problem Overview


I made acommit and pushed it to origin and heroku

Then I realised it was wrong, so I did

git reset --soft HEAD^ 

But when I'm pushing to Heroku Im getting

To [email protected]:app.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to '[email protected]: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)

Git Solutions


Solution 1 - Git

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.

Solution 2 - Git

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

Solution 3 - Git

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:

  1. So first git reset --hard origin/master or git reset --hard heroku/master (or whatever your heroku tracking branch is called), in order to get your local master back the bad commit. This will blow away any outstanding changes in your working copy, so be careful.

  2. Then git revert HEAD to create a new commit (it will prompt you for a commit message).

  3. Then push as you usually would.

Solution 4 - Git

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMartinView Question on Stackoverflow
Solution 1 - GitJohn BeynonView Answer on Stackoverflow
Solution 2 - GitDeviView Answer on Stackoverflow
Solution 3 - GitDave GoodellView Answer on Stackoverflow
Solution 4 - GitBenjamin AtkinView Answer on Stackoverflow