Search code examples
gitreset

Recover lost files after added and doing git reset --hard


How to recover files after adding and doing git reset --hard?

Here are some points that must consider before answer:

  • Raw .git directory
  • No initial commit
  • .git directory has size of 67.3 MBs

Sequence of git commands that cause damage

  1. git add .
  2. git reset --hard

Kindly help me out to recover my project source code files.


Solution

  • if you have your .git folder go to your project dir in which .git folder lies. use this

    git fsck --lost-found

    it will generate a folder in .git directory lost-found you can see a blob there,it hasn't named files but you can see your code in these files.