GitHub删除了我以前的提交

时间:2017-07-06 04:14:05

标签: github github-for-windows

请!我失去了一整天的工作。

我创建了一个github存储库......我整天都在做git add -A和commit,但我从未做过推动。我直接在页面上更改了自述文件(不知道我将在合并这些相同的分支时遇到问题)。

当我试图在一整天后进行git push时,发生了以下情况:

To https://github.com/NEGU93/Steganography.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/NEGU93/Steganography.git'
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.

所以我尝试了ta git pull --rebase,但它开始崩溃一些我不知道它是什么的东西:

remote: Counting objects: 3, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/NEGU93/Steganography
   6161279..44d1f0f  master     -> origin/master
      0 [main] expr 8516 open_stackdumpfile: Dumping stack trace to expr.exe.stackdump
      0 [main] cat 15632 open_stackdumpfile: Dumping stack trace to cat.exe.stackdump
      0 [main] rm 4660 open_stackdumpfile: Dumping stack trace to rm.exe.stackdump
^C

我把ctrl + C用来阻止那里的崩溃。所以我做了一个git fetch,然后是我的工作:

fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use

    git push origin HEAD:<name-of-remote-branch>

所以我按照建议做了并且做了一个git push to master:

git push origin HEAD:master
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 1.49 KiB | 0 bytes/s, done.
Total 5 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/NEGU93/Steganography.git
   44d1f0f..c3b8393  HEAD -> master

但是现在当我回来时,工作不在那里......救命!我不知道该怎么办,我开始恐慌。我认为问题在于git fetch。有没有办法让我的所有工作都恢复?

1 个答案:

答案 0 :(得分:0)

使用git reflog查看过去的提交,然后使用提交的哈希来重置,例如:

git reset --hard e870e41

请参阅How can I recover a lost commit in Git?