I have a .NET solution which, after switching back to master
branch, leaves a project folder behind. I want to clean this folder up (there is nothing but bin and obj folders inside, with some old dll's) so I tried git clean -f -d
. This did not work.
I checked which files are being tracked by git using git ls-tree test/flat -r --name-only
and sure enough the project folder to be cleaned is not listed.
What should I do to convince git to clean the working folder so that it's contents is only what is in the master
branch?
Note: The unwanted project folder is also not ignored.
If there are ignored files in that folder, git clean
won't remove the folder.
The options you want to look into, possibly using all three of them are:
-f
: force git clean to delete the files-d
: delete untracked directories in addition to untracked files-x
: delete files that are ignored by gitThis command:
git clean -fdx
Should remove all untracked files and directories.
NOTE! And I say this because many doesn't read the warning labels, if you do this, you can't get those files back. They're gone. You will need to have disk- or file-level backup other than git to restore those files.
Use "git clean -ifdx" to delete files and directories interactively. This way you can avoid accidental delete of a file. Git shows you the list of file that will be deleted and asks you to choose from the option.
git clean
will not remove files that are being ignored by git by default.
Add the -x flag to remove ignored files as well or the -X flag to remove only ignored files and directories
git clean -fdx
git clean -fdX
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With