Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using `git clean` in a folder deleted its contents

Tags:

git

I was trying to use Git in a folder then I used git glean -df and I found everything gone.

Does that mean I lost my files and is there any way to get them back?

like image 682
E. Aly Avatar asked Feb 27 '26 18:02

E. Aly


1 Answers

When you ran git clean -df you asked Git to

Remove untracked files from the working tree

including directories. You also told Git to ignore its safety net.

If Git knows about the files (i.e. if they've ever been added or stashed, even if they were never commited) then they should be recoverable. Try running git fsck --cache --no-reflogs --lost-found --unreachable and then looking in .git/lost-found/ for objects that you deleted.

Otherwise there is no way for Git to retrieve them; you'll have to rely on other tools like an existing backup, filesystem snapshots, file synchronization tools, or filesystem recovery tools.

like image 111
Chris Avatar answered Mar 02 '26 06:03

Chris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!