意外删除了我对Git的所有提交 - 发生了什么?

时间:2016-05-09 23:16:54

标签: git github

好吧,让我开始说我非常讨厌git。我收到错误消息后收到错误消息,导致我的项目的每个提交都被删除。以下是我最近执行的命令:

git push origin master

给了我一个错误:

error: failed to push some refs to '[repository link here]'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

然后我在网上找到了一个资源并做了这个:

git pull origin master
git push -f origin master

然后一切都消失了,除了一次提交。我该怎么做才能恢复?

2 个答案:

答案 0 :(得分:0)

Git警告你,你所要做的事情具有破坏性。当你做git push -f这是一个强迫推动,你告诉Git继续这样做。无论你在当地拥有什么,都将取代遥控器中的任何东西。

答案 1 :(得分:0)

当你第一次尝试推送时,你已经提交了远程仓库。 Git无法推送,因为您需要将更改提取到本地仓库并合并它们才能推送新提交。

但是,通过使用-f,您强制远程仓库覆盖服务器上的提交。