正如我所想,我最近想更新远程 git 存储库上的代码。我没有意识到它甚至还没有 promise 。我确实创建了一些错误,所以我想将分支重置到之前的状态。
正如您所料,我使用了git reset --hard
。
好吧,从那以后一切(整个项目)都消失了;当然,.gitignore
文件/文件夹除外。我一直在想,有什么办法可以挽回吗?
我所做的唯一步骤:
git add .
# Here I realized there is a bug in what I did
# I thought myself it would be better to undo that as it wasn't even something needed
git reset --hard
另外,我想指出,它可能与这里的任何问题都不重复,因为其他人之前已经进行过一些提交。这是全新的存储库,并且已被“硬重置”。
最佳答案
您可以将文件恢复到添加时的状态,但不显示文件名。使用 git fsck ,您可以获得任何提交都未引用的文件列表。
$ git fsck
Checking object directories: 100% (256/256), done.
Checking objects: 100% (1/1), done.
dangling blob c7c49b553f1b8c3c8f7955780e5dfdb934ce26db
dangling tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904
dangling blob 4f92ab465171608a2c713f2f5439143df2c8afc9
dangling blob 9c1216eb500c0fc2c55c263a9cf221f282c3cd7b
然后就可以使用git cat-file
来获取文件内容:
for blob in `git fsck | grep 'dangling blob' | cut -d\ -f3` ; do git cat-file -p $blob > $blob ; done
或者您也可以使用git fsck --lost-found
,它将所有悬空对象放入.git/lost-found/
关于git - 在没有任何提交的情况下撤消 git Reset,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48518040/