I accidentally run the command "git clean -df", so I lost many directories and files, I want to recover them, I don't have backup in time machine. I tried some software to recover, but they don't work.

  • 1
    You can't recover files after deleting them. The only way would be to immediately shut down your Mac, WITHOUT modifying ANY part of the HD, then use a HD Recovery Program. You probably already lost your data, as it gets overwritten by new files. Let this be a lesson to use Time Machine or some other backup software, especially when using terminal commands that delete stuff.
    – At0mic
    Nov 10, 2015 at 21:20
  • Are you sure that files have been deleted in the online repository? If you are working in the local repository and you have one up-to-dated online, you can download the last online version using git clone or git pull.
    – rebatoma
    Nov 10, 2015 at 21:45
  • @IronCraftMan thank you for your reply, do you know is there some good software for recovering files for mac OS X? I am almost try every method, but failed T.T
    – llyjy21
    Nov 11, 2015 at 7:52
  • @llyjy21 as I said, you probably already overwrote the data. By installing that other Software, and whatever else you did, OS X could have modified the HD. It's too late. Since every method has failed, I'd give up. Next time backup your data.
    – At0mic
    Nov 11, 2015 at 16:06
  • Same question on SO: stackoverflow.com/questions/6267180/can-i-undo-a-git-clean-fdx
    – Flimm
    Dec 21, 2016 at 17:00

2 Answers 2


If you are working with an online repository and you keep it up-to-date you can download all the file from the online repository using the following commands:

git pull                            # in the case the remote is set
git clone <address_of_repository>   # in the case the remote is not set

Using these commands you'll be able to restore your deleted files, obviously only if the online repository is up to date.

  • 1
    Nope, I mean it delete all my folders and files in my local machine, not related to git
    – llyjy21
    Nov 11, 2015 at 7:50
  • In this particular case the only solution is follow what IronCraftMan suggested to you.
    – rebatoma
    Nov 11, 2015 at 7:56
  • haha, thank you, but i prefer IronMan. haha
    – llyjy21
    Nov 11, 2015 at 11:18

I also ran into same issue unknowingly ran git clean -df and git clean -xf, but fortunately I am using php storm and it saves local history by which I am able to recover the deleted files.

If you are also using any IDE then check if it has local history.

  • No. The answer is to use a proper backup regime. This covers all files as asked in the question. An IDE might protect some files but that is not its purpose, definitely not non source code files and in the OPs case the backups the IDE keeps might have been deleted as well.
    – mmmmmm
    May 7, 2021 at 14:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .