[英]Restore files from git
I worked on a new Projekt. 我在一个新的Projekt上工作。 I added all the Files to my local git-repository
我将所有文件添加到本地git存储库
git add .
but i didn't commit it. 但我没有承诺。 Then i accidently resetet the git
然后我不小心重置了git
git reset --hard
How is it possible to restore my Files? 如何还原我的文件? I hoped, that atom kept the files, but also there, the files where not open anymore.
我希望那个原子保留文件,但也保留那些不再打开的文件。 Nevermind, that atom would close all my files.
没关系,那个原子会关闭我的所有文件。
When you git add
a file, git
stores it as an object in your repository (in the .git
directory). git add
文件时, git
将其作为对象存储在存储库中( .git
目录中)。 Your files are probably still hanging around. 您的文件可能仍在徘徊。 On the other hand, by running the
git reset --hard
command you have lost any information about the file names . 另一方面,通过运行
git reset --hard
命令,您丢失了有关文件名的任何信息。
You can see the objects themselves by running: 您可以通过运行以下命令查看对象本身:
find .git/objects -type f
Which will produce something like: 会产生类似:
.git/objects/67/6e8ff99e42b61f96bb0107fa1dff59594eba07
.git/objects/7c/45d8f7d987c584a8d61a8d75431ddd4f1ba52f
You can see the contents of those objects with the git cat-file
command, as in: 您可以使用
git cat-file
命令查看这些对象的内容,如下所示:
git cat-file -p 7c45d8f7d987c584a8d61a8d75431ddd4f1ba52f
Note that the object id is the concatenation of the two characters in the first level directory followed by all the characters of the filename. 请注意,对象ID是第一级目录中两个字符的连接,后跟文件名中的所有字符。
So it would be fairly trivial to write a script that would restore the contents of all your files, but you would have to manually rename them after the fact. 因此,编写一个脚本来还原所有文件的内容是相当琐碎的,但是您必须在事后手动重命名它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.