0

Unknowingly I deleted my all important files. Firstly, I initialized my directory using git init then I added the files using git add . after that to unstage my files I run this command "git rm -r . -f" which removed all my files from my local computer.

PS C:\Users\ABDUL WAHAB\Desktop\jup> git init
PS C:\Users\ABDUL WAHAB\Desktop\jup> git add .
PS C:\Users\ABDUL WAHAB\Desktop\jup> git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   .ipynb_checkpoints/Basic_Data_Analysis_Assignment-checkpoint.ipynb
        new file:   .ipynb_checkpoints/Basic_Data_Analysis_Assignment_2-checkpoint.ipynb
        new file:   .ipynb_checkpoints/Basic_Data_Analysis_Assignment_2_Solution-checkpoint.ipynb
        new file:   .ipynb_checkpoints/Basic_Data_Analysis_Assignment_Solution-checkpoint.ipynb
        new file:   .ipynb_checkpoints/Corona Virus Data-checkpoint.ipynb
        new file:   .ipynb_checkpoints/Data_Engineering_Summer_Analytics-checkpoint.ipynb
        new file:   .ipynb_checkpoints/Numpy Tut-checkpoint.ipynb
        new file:   .ipynb_checkpoints/PandaNotes-checkpoint.ipynb
        new file:   .ipynb_checkpoints/Pandas Tut-checkpoint.ipynb
        new file:   .ipynb_checkpoints/Web Scraping- Trump's Lies-checkpoint.ipynb
        new file:   Basic_Data_Analysis_Assignment.ipynb
        new file:   Basic_Data_Analysis_Assignment_2.ipynb
        new file:   Basic_Data_Analysis_Assignment_2_Solution.ipynb
        new file:   Basic_Data_Analysis_Assignment_Solution.ipynb
        new file:   Corona Virus Data.ipynb
        new file:   Data_Engineering_Summer_Analytics.ipynb
        new file:   Numpy Tut.ipynb
        new file:   PandaNotes.ipynb
        new file:   Pandas Tut.ipynb
        new file:   Web Scraping- Trump's Lies.ipynb
        new file:   trump_lies.csv
        new file:   weather.csv
        new file:   weather.txt

After doing this like everyone, then I did this disaster.

PS C:\Users\ABDUL WAHAB\Desktop\jup> git rm -r . -f
rm '.ipynb_checkpoints/Basic_Data_Analysis_Assignment-checkpoint.ipynb'
rm '.ipynb_checkpoints/Basic_Data_Analysis_Assignment_2-checkpoint.ipynb'
rm '.ipynb_checkpoints/Basic_Data_Analysis_Assignment_2_Solution-checkpoint.ipynb'
rm '.ipynb_checkpoints/Basic_Data_Analysis_Assignment_Solution-checkpoint.ipynb'
rm '.ipynb_checkpoints/Corona Virus Data-checkpoint.ipynb'
rm '.ipynb_checkpoints/Data_Engineering_Summer_Analytics-checkpoint.ipynb'
rm '.ipynb_checkpoints/Numpy Tut-checkpoint.ipynb'
rm '.ipynb_checkpoints/PandaNotes-checkpoint.ipynb'
rm '.ipynb_checkpoints/Pandas Tut-checkpoint.ipynb'
rm '.ipynb_checkpoints/Web Scraping- Trump's Lies-checkpoint.ipynb'
rm 'Basic_Data_Analysis_Assignment.ipynb'
rm 'Basic_Data_Analysis_Assignment_2.ipynb'
rm 'Basic_Data_Analysis_Assignment_2_Solution.ipynb'
rm 'Basic_Data_Analysis_Assignment_Solution.ipynb'
rm 'Corona Virus Data.ipynb'
rm 'Data_Engineering_Summer_Analytics.ipynb'
rm 'PandaNotes.ipynb'
rm 'Pandas Tut.ipynb'
rm 'Web Scraping- Trump's Lies.ipynb'
rm 'trump_lies.csv'
rm 'weather.csv'
rm 'weather.txt'

Can anyone help me how to restore those files?

1 Answers1

0

Anything that you've added with git add will still be in your repository, at least temporarily. You can run git fsck --lost-found to find the objects which are dangling (that is, not associated directly or indirectly with any ref).

You'll get output like this:

dangling blob 83455250c43390ce653e10935b7b5ae743000ff7
dangling commit b35bb2d9ebf399dc6292a99d00cf75a362405815
dangling commit c082520240cc90f93b0c4c4b045e2011652b8b31
dangling blob a08f72e1406444d4e7196562a5894c5a4838c21c

You can then grab one of those blobs with git cat-file blob OBJECT_ID and look at its contents. If it's something that you want to save, just redirect it to an appropriately named file (e.g., git cat-file blob 83455250c43390ce653e10935b7b5ae743000ff7 >weather.txt). Note that the non-blobs are probably not very interesting to you in this case, so if you find any of those, you can just skip them.

Also, may I suggest the -n (--dry-run) option in the future for git rm and git clean? I've found it helpful, at least.

bk2204
  • 64,793
  • 6
  • 84
  • 100