Recover directory removed with git rm -rf
我使用
是的,你可以,
请阅读:如何撤消Git中的更改。
将文件添加到Git后,它们就开始被跟踪,并存储在
在中,它们只是被添加而从未被提交,它们被称为
首先我们得找出他们
1 | git fsck --full |
一旦你有了这些对象的列表,你就需要查看它们并找出你需要的对象。
1 2 3 4 5 | # Print out the content of the Object git cat-file -p <SHA-1> # If the object is a file you will simply see its content, # Copy it and save it in a new file. |
这里是recover.py实用程序,它将为每个哈希创建一个文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | enter code here import subprocess hashes=["01b6a7f272375bc99d98be0068c273b5bc4e9ff6", "03620d7b53c8a48314c25a3ecdbe369553b01340","PUTYOUR HASHEZ HERE"] for myhash in hashes: print"HASH", myhash bashCommand ="git cat-file -p"+ myhash process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE) output, error = process.communicate() file = open("recover/"+myhash,"w") file.write(output) file.close() |
这将写入恢复文件夹所有用git杀死的文件