How do I recover my staged files but not earned ones?
If your files were delivered as you said, you can get them back with an git fsck
option command --lost-found
.
If you run git fsck --lost-found
, you'll see something like this (with potentially more dangling blob lines):
Checking object directories: 100% (256/256), done.
dangling blob 84eab6f56e81cebe1356c9c2a6e2882c05f5fc01
Some of these dangling drops may be your missing files.
If you run git show <SHA of a dangling blob>
, you will be able to see the contents of this file, unfortunately the filenames will most likely be lost.
However, you can copy the output back to the appropriate files. Also, once started, the git fsck --lost-found
dangling blobs will be saved in a directory .git/lost-found/other/
at the root of your repository.
source to share
Yes, if you've arranged your changes, you can get your files back completely. When you run git add
, the files are actually added to the Git object database. At this point, Git will index the file:
% git add bar.txt
% git ls-files --stage
100644 ce013625030ba8dba906f756967f9e9ca394464a 0 bar.txt
100644 6af0abcdfc7822d5f87315af1bb3367484ee3c0c 0 foo.txt
Note that the entry for bar.txt contains the file object ID. Git has actually added the file to its object database. In this case, Git added it to the repository as a free object:
% ls -Flas .git/objects/ce/013625030ba8dba906f756967f9e9ca394464a
4 -r--r--r-- 1 ethomson staff 21 14 Jun 23:58 .git/objects/ce/013625030ba8dba906f756967f9e9ca394464a
Eventually these files will be collected in trash. But this will happen within a few months, not days. Until these files are collected, you can restore them.
The easiest way to do this is to download and install the programgit-recover
online:
% git recover -i
Recoverable orphaned git blobs:
61c2562a7b851b69596f0bcad1d8f54c400be977 (Thu 15 Jun 2017 12:20:22 CEST)
> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
> tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
> veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
> commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
Recover this file? [y,n,v,f,q,?]:
git-recover
looks for files in the object database that were not committed (or in the index). You can learn more about git-recover
in a blog post announcing it .
source to share