[英]How to restore repository after git push -force?
I was connected to my github repository but got the following error when I tried to push a file: 我已连接到github存储库,但在尝试推送文件时收到以下错误:
To https://github.com/name/port.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://github.com/name/port.git' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (eg 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details.
After looking through the guide, I found the -force option and forced a push: 浏览完指南后,我找到了-force选项并强行进行了推送:
git push -f
but now everything in that repository has been overwritten. 但是现在该存储库中的所有内容都已被覆盖。 How do I revert back to an earlier commit?
如何恢复到较早的提交? Sorry, I'm new to github and I would appreciate any help!
抱歉,我是github的新手,我将不胜感激!
You'll want to use git reflog
. 您将要使用
git reflog
。 Git doesn't remove commits from its database until you run git gc
. 在运行
git gc
之前,Git不会从其数据库中删除提交。
git reflog
ABCD1234 HEAD@{0}: Boom goes the dynamite! Your repository is hosed!
...
EFGH5678 HEAD@{n}: Last known good commit
*shift + Q to exit*
git reset --hard EFGH5678
git push -f
Note: This has nothing to do with GitHub. 注意:这与GitHub无关。 This is behavior in Git itself you are noticing.
这是您注意到的Git本身的行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.