1

I had a old project which I wanted to add git to. I run

git init

and after that I added .gitignore file. The error I did is that I haven't commit anything first but I wanted to see if my gitignore file works so I run

git add .

I noticed that there are more files I wanted to exclude (whole project is 45GB with assets) so I run

git reset --hard

and this mess up my whole repo. I lost all of the files except the ones listed in gitignore and I cannot do anything.

git status

shows me a files listed in git ignore and if I run

git reflog

or even

git log

I have this error

fatal: your current branch 'master' does not have any commits yet

Please let me know how can I restore my project?

Greg
  • 25,317
  • 6
  • 53
  • 62
  • possibly related https://stackoverflow.com/q/9750049/7926064 - sorry for your loss. Do you have filesystem snapshots maybe? – BNT Feb 08 '18 at 09:44
  • @LasseVågsætherKarlsen git keep everything as SHA hash which I'm sure you can restore somehow (the project size shows that the files are there). Maybe there is some way I can get the files from the hash even if I need to do it manually file by file? – Greg Feb 08 '18 at 09:48
  • You're right, git add added all the files to the repository, however it didn't add a commit object. You can possibly fake a commit object unless you want to go digging manually. If you check the .git\objects folder you'll find all your files in a compressed manner (there may even be packfiles with some of the stuff), but it's going to be a bit of work to restore. See if there are plumbing commands. – Lasse V. Karlsen Feb 08 '18 at 09:50
  • @Greg see https://stackoverflow.com/questions/25791533/unstaged-files-gone-after-git-reset-hard/25792257#25792257 – BNT Feb 08 '18 at 09:51
  • @LasseVågsætherKarlsen do you know how can I do? I'm not git expert. – Greg Feb 08 '18 at 09:51
  • Also see https://stackoverflow.com/questions/3364575/whats-the-best-way-to-extract-a-tree-from-a-git-repository - for a way to read the index from a tree object and check it out, it may work for you. – Lasse V. Karlsen Feb 08 '18 at 09:51
  • Sorry, I'm not an expert on the plumbing commands. Seeing as you don't have a single commit, any tree objects which are not referred to by other tree objects is probably going to be the root tree. – Lasse V. Karlsen Feb 08 '18 at 09:52
  • 1
    and do create a backup of the whole folder now :) – BNT Feb 08 '18 at 09:52
  • @BNT I'm doing that now, thanks. Once done I try so of the above suggestion. – Greg Feb 08 '18 at 09:54
  • Looks like the tree objects are not created until you create the commit. – Lasse V. Karlsen Feb 08 '18 at 09:58
  • You can’t reset on a branch with no commits. – evolutionxbox Feb 08 '18 at 13:17
  • Thanks Guys. I manage to find a back up so I'm ok. – Greg Feb 08 '18 at 13:24

0 Answers0