Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restore files that were removed by git?

Tags:

git

I am a git noob and git just deleted a bunch of important files. How do I get them back?

I have a repo on my local machine. To get into git, I just right click my project folder and select "git bash here". This brings up the master where I do all my giting.

So I had some changes to stage and I did:

git add .

This staged a bunch of changes. I noticed that I didn't want some of these staged so I decided that I'd try to unstage everthing. I did this:

git reset --hard HEAD^

This basically deleted a bunch of files that I had made on the last commit and jumped to the commit before.

How do I get those files back? If I can't do it through git is there another way?

like image 398
Ryan Avatar asked May 06 '10 10:05

Ryan


1 Answers

I stand corrected regarding my original advice (see edit history). As penance, I've tracked down the simplest way to recover your lost files from git:

git fsck --lost-found
ls .git/lost-found/other

Unfortunately, the filenames are lost, but the contents should all be there as distinct files.

like image 82
Marcelo Cantos Avatar answered Sep 21 '22 02:09

Marcelo Cantos