Git 恢复 heroku 中的最后一次提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5248103/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git revert last commit in heroku
提问by Martin
I made acommit and pushed it to origin and heroku
我做了一个承诺并将它推送到 origin 和 heroku
Then I realised it was wrong, so I did
然后我意识到这是错误的,所以我做了
git reset --soft HEAD^
But when I'm pushing to Heroku Im getting
但是当我推动 Heroku 时,我得到了
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)
我明白这个问题。我应该如何进行?我怎样才能恢复最后一次 heroku 提交?(我认为这将是最好的解决方案)
回答by John Beynon
If you've reverted the commit locally you may need to git push
with a -f
option to force the commit in.
如果您已恢复本地提交你可能需要git push
用一个-f
选项来强制提交英寸
Also, you may want to have a look at Heroku releaseswhich may help too.
此外,您可能想看看Heroku 版本,这也可能有所帮助。
回答by Devi
From http://devcenter.heroku.com/articles/releases#rollback
来自http://devcenter.heroku.com/articles/releases#rollback
Use the rollback command to roll back to the last release:
使用 rollback 命令回滚到上一个版本:
$ heroku rollback
Rolled back to v51
You may choose to specify another release to target:
您可以选择指定另一个版本作为目标:
$ heroku rollback v40
Rolled back to v40
回答by Dave Goodell
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:
鉴于您已经推送到其他(公共?)存储库,解决此问题的最佳方法可能是在git reset
本地撤消,然后git revert
创建一个新提交,以扭转错误提交的影响。然后再次推动一切。所以一步一步:
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.
所以首先
git reset --hard origin/master
或git reset --hard heroku/master
(或任何你的heroku跟踪分支被调用),为了让你的本地master
恢复错误的提交。这将消除工作副本中任何未完成的更改,所以要小心。然后
git revert HEAD
创建一个新的提交(它会提示您输入提交消息)。然后像往常一样推动。
回答by Benjamin Atkin
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:
然后我push -f
将本地 repo 上的旧分支运行到 heroku 的主人:
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