问题描述
我从 git reflog
尝试了 git reset --hard HEAD @ {n}
,我失去了一切我的当前非分页文件:'(
未分离的文件是最后一个 git add
git reset
到最后一个 git commit
。
我的所有文件都没有了,我无法在上次提交之前返回 git add
:'(
目前还不清楚在工作目录中是否丢失了文件,或者是
文件中的文件,你说你丢失了unstaged files,但是你提到了
you可能已经运行了git add,unstaged files丢失了。
分段文件可以通过
git fsck --full --unreachable --no-reflog
对于添加的每个文件,都会有一个丢失的blob对象,并且对于每个
目录条目都会有一个树对象。您将恢复您的
文件chang
git cat-file -p SHA
对于您修改的每个文件
(主)$ vi bar
(master)$ vi baz
(master)$ vi foo
(master)$ git add foo bar baz
(master)$ git reset --hard HEAD
HEAD is现在在ead8fa2初始
(master)$ git fsck --full --unreachable --no-reflog
检查对象目录:100%(256/256),完成。
可达BLOB 0c29287001b29159f11c4e8a320bce7e9789c00b
可达BLOB 1524d3478e3d0b92866a53239b10bcd4b3838c4d
可达BLOB 97b724e770249816c61d8a526415986208ed7e15
//看看对象
(主)git的猫文件的一个-p 0c29287001b29159f11c4e8a320bce7e9789c00b
变为bar
//这里,基于检查输出,我可以确定0c29287是文件bar
(master)git cat-file -p 0c29287> bar
(注意我测试时没有丢失任何树,所以这部分可能不起作用) p>
如果您修改了大量文件,则通过树对象而不是单个文件恢复
可能更容易
git读取树SHA
其中SHA是为根树丢失的树对象。
I tried the git reset --hard HEAD@{n}
from git reflog
and I lost everything with my current unstaged files :'(
the unstaged files is the last git add
I did, before then I tried git reset
to the last git commit
.
And all my files gone, I can't go back to the git add
before last commit :'(
It's not clear if you lost files in your working directory, or files inthe index. You say you lost your "unstaged files", but then you mentionyou might have run "git add". "unstaged files" are lost for good.
Staged files can be recovered with
git fsck --full --unreachable --no-reflog
For each file added there will be a lost blob object, and for eachdirectory entry there will be a tree object. You would recover yourfile changes by doing
git cat-file -p SHA
For each file that you had modified
(master)$ vi bar(master)$ vi baz(master)$ vi foo(master)$ git add foo bar baz(master)$ git reset --hard HEADHEAD is now at ead8fa2 initial(master)$ git fsck --full --unreachable --no-reflogChecking object directories: 100% (256/256), done.unreachable blob 0c29287001b29159f11c4e8a320bce7e9789c00bunreachable blob 1524d3478e3d0b92866a53239b10bcd4b3838c4dunreachable blob 97b724e770249816c61d8a526415986208ed7e15// take a look at one of the objects(master)git cat-file -p 0c29287001b29159f11c4e8a320bce7e9789c00bchanges for bar//Here, based on inspecting the output, I can determine that 0c29287 was the file "bar"(master) git cat-file -p 0c29287 > bar
(note I didn't get any lost trees when I tested, so this part may not work)
If you modified a whole bunch of files it is probably easier to recovervia the tree object instead of individual files
git read-tree SHA
Where SHA is the lost tree object for the root tree.
这篇关于git重置后未归档的文件消失了--hard的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!