我连接到我的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 (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
查看指南后,我找到了-force选项并强制推送:
git push -f
但现在该存储库中的所有内容都被覆盖了。如何恢复到之前的提交?对不起,我是github的新手,我将不胜感激!
答案 0 :(得分:0)
您需要使用git reflog
。在您运行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
注意:这与GitHub无关。这是你注意到的Git本身的行为。