2

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.

Mudassar
  • 508
  • 4
  • 13
  • 1
    Possible duplicate of [Recovering added file after doing git reset --hard HEAD^](https://stackoverflow.com/questions/1108853/recovering-added-file-after-doing-git-reset-hard-head) – Bhargava Nandibhatla Oct 20 '18 at 05:42
  • I tried that solution but it didn't work for me. – Mudassar Oct 20 '18 at 05:45
  • 2
    And https://stackoverflow.com/questions/10782978/recover-files-that-were-added-to-the-index-but-then-removed-by-a-git-reset/10783950#comment42371725_14988152? `for b in $(git fsck --lost-found | grep blob | awk '{print $3}'); do git cat-file -p $b > ../$b ; done` – VonC Oct 20 '18 at 06:52
  • Which operating system do you use? – ImGroot Oct 20 '18 at 08:17
  • I'm using windows 8.1 x64 – Mudassar Oct 20 '18 at 08:29

1 Answers1

2

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.

Muhammad Azam
  • 535
  • 7
  • 12