Reputation: 21556
I've just updated my .gitignore file to not include node and bower module files.
node_modules/
.tmp
.sass-cache
sample/bower_components/
sample/node_modules/
sample/images/
But when I run git clean -f
, my terminal responded with
Removing sample/scripts
of course, the sample/scripts
is the folder that I want to keep in the project, and I haven't specified it in the .gitignore, so why is it being removed??
Upvotes: 0
Views: 406
Reputation: 388143
git clean
will remove files that are not known to Git. If you don’t pass the -x
flag, it will remove files that are not tracked and not explicitely ignored.
So if sample/scripts
was removed, then it was obviously not tracked by Git. If you want to keep it, you have to track it by adding and commiting it, or also add it to the .gitignore
.
Btw. it’s a good idea to always run git clean -n
first to see what Git would remove before it actually does that.
Upvotes: 4
Reputation: 20486
I'm assuming you haven't added any files from sample/scripts
directory to the Git repository. This means they aren't tracked and from the git-clean
manual they will be removed: Cleans the working tree by recursively removing files that are not under version control, starting from the current directory.
You can check what files are being tracked by your local repository with:
git ls-tree --full-tree -r HEAD
If files are missing, just add them:
git add sample/scripts/.
git commit -m "Add missing sample scripts"
git clean -f
Git just tracks files, so blank directories won't count. You can add a basic .gitignore to fix this:
touch sample/scripts/.gitignore
git add sample/scripts/.gitignore
git commit -m "Add sample scripts gitignore"
git clean -f
Upvotes: 0