-1

Hmm, I screwed up...

I have a repo and did a git add . for the first time.

But then realised there are a lot of files that should not be there, so I wanted to reset and then fix the .gitignore en then redo.

after doing git reset --hard

all my files are gone.

Question, is there a way to "undo" this?

Desperate for help. I have no other backup, pushing to git was supposed to be my backup ;>)

Mikkie
  • 103
  • 2
  • 11

2 Answers2

0

This link provided the method to recover the files.

git add + git reset hard deleted working copy file - undo?

It was a bit of a pain, but better than redoing all the work.

I used this command to list all the blobs into a text file (blobs.txt).

git fsck | awk '{if(/blob/) print $3}' > blobs.txt^C

Then I wrote a short bash script to loop through the file and cat the contents of each blob to a file. Here is the bash script:

#!/bin/bash
while read p; do
        git cat-file blob $p > $p.txt
done <blobs.txt

That gave me a load of files named blobxxx.txt Then I had to manually go through each and determine the filename I needed. Bit of a process, but it worked since I only needed to find my source files.

BIG SIGH OF RELIEVE.

Mikkie
  • 103
  • 2
  • 11
-2

Basically, the answer is no. As you said you screwed up. For more detailed answer please follow this post: Recover from git reset --hard?

Joik
  • 175
  • 7