Git deleted all my files
I just ran
git clean -df in my home directory and all of my files were removed. Could anyone explain this problem? I think I accidentally committed my home directory a couple years back and this caused it to roll back to a later version? But how would I of committed it if there was no place to push it to.
Update: I found out that I created the project in the home directory.
2 Solutions collect form web for “Git deleted all my files”
… caused it to roll back to a later version?
That’s not what
git clean does. It simply removes any files that aren’t currently tracked by Git. It does not change tracked files which contain modifications.
But how would I of committed it if there was no place to push it to.
That has nothing to do with how Git works. You do not need to push anything anywhere in order to initialize a repo and begin committing things to it.
If you initialize a repository in a directory that has files, that’s fine. Now your repository has 0 tracked files, and every file that was already present is an untracked file.
You then told Git to delete all untracked files, and confirmed that you did indeed want Git to do this destructive action with the
-f flag. To make it worse, you used
-d to tell Git to recursively descend into directories and delete any untracked files it finds there too.
See the documentation for
Remove untracked directories in addition to untracked files. If an untracked directory is managed by a different Git repository, it is not removed by default. Use -f option twice if you really want to remove such a directory.
If the Git configuration variable clean.requireForce is not set to false, git clean will refuse to run unless given -f, -n or -i.
Basically you told git to remove all files in the current directory that it didn’t know about