Yes, it will delete them. If you pass
-f you’re telling it to forcibly do it as well, which is a bit dangerous. Regardless of which option is used, if you have forgotten to commit file/s you meant to commit, the command will just fry them. There’s not going to be anything you can do about it.
It’s normally for doing something like wiping out build directories/files that shouldn’t be committed.
--hard will remove any files that have appeared since, so in that respect, yes, it may exhibit similar behaviour. And it will nix all changes to existing files. Without
--hard it will unstage all changes made after the commit, which is the command’s normal behaviour.
It is the opposite of
So if you’ve added some files to be committed that you didn’t mean to, you can run
git reset to unstage them, then add the ones you actually wanted to add.
Note you’ll likely get into a mess if you try to go back and unstage commits that were done by other people, but it’s normally fine if it’s just a series of your commits.
Note that if you type
into the terminal that will give you the documentation for
git clean, and if you type
it will give you the documentation for