git 恢复到 Bitbucket 中的旧提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37433958/
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
Revert to an old commit in Bitbucket
提问by me9867
I have git setup on my web hosting and on an account at Bitbucket which are both linked.
我在我的虚拟主机上和 Bitbucket 的一个帐户上都有 git 设置,它们都已链接。
How can I revert back to my first commit on both my hosting (which I am logged into via SSH and has git installed ready and working) and on Bitbucket?
我怎样才能在我的主机(我通过 SSH 登录并且已经安装好 git 并且可以工作)和 Bitbucket 上恢复到我的第一次提交?
I have tried: git checkout 965a793
我试过了: git checkout 965a793
Then I tried with a dot on the end: git checkout .
然后我尝试在最后加一个点: git checkout .
but nothing seems to change on the Bitbucket side, when I got to git push. It says everything is up to date, even though Bitbucket is on commit cf08232
但是当我使用 git push 时,Bitbucket 方面似乎没有任何变化。它说一切都是最新的,即使 Bitbucket 正在提交cf08232
Here is a list of my three commits:
这是我的三个提交的列表:
cf08232 remove the txt file
096d08f test.txt edited online with Bitbucket
965a793 Initial Commit
回答by khrm
Use --force :
使用 --force :
git reset --hard commitID
git push origin branchName --force
I am assuming origin is the remote of bitbucket
我假设 origin 是 bitbucket 的远程
回答by Nicola
Please note git resetis dangerous. I personally am not a fan because it deletes/modifies change history. If you want to rollback your changes to a specific commit without modifying the change history, I suggest using git revert instead:
请注意git reset是危险的。我个人不是粉丝,因为它会删除/修改更改历史记录。如果您想在不修改更改历史记录的情况下将更改回滚到特定提交,我建议改用 git revert:
git revert cf08232
git revert 096d08f
Each time you run git revert, it will create a new commit that undoes the changes introduced by a specific prior commit, without modifying the change history.
每次运行 git revert 时,它都会创建一个新提交,该提交撤消由特定先前提交引入的更改,而不会修改更改历史记录。
Here's a good articlethat compares reset, checkout & revert.
回答by CodeWizard
Read this full answer on how to do it.
阅读有关如何操作的完整答案。
How to move HEAD back to a previous location? (Detached head)
It will explain each option in detail.
它将详细解释每个选项。
basically - checkout the desired commit and push it remote.
基本上 - 签出所需的提交并将其推送到远程。