Undo a git clean command?

James Brown picture James Brown · Apr 5, 2013 · Viewed 9.9k times · Source

I just used a "git clean" command and managed to delete my Documents, Music, and other directories. Is there a way to undo this and somehow get those files back? I did this via Terminal on Mac. Time Machine isn't setup either.

Answer

Gabriele Petronella picture Gabriele Petronella · Apr 5, 2013

I'm afraid those files are gone. git clean is not reversible since those files were not tracked by git.

From the comments it looks like you had your home folder as git repo, but with nothing tracked.

Running git clean -f removed any file inside the home folder (included the one in the subdirectories), leaving only empty subdirectories (the -d option is required for removing them too).

I'm sorry to inform you that you definitely wiped out your whole home directory. Next time you run a git clean use the -n options to perform a dry run and check what's going to happen before it's too late.