With .gitignore
:
foo/
and a git repository of:
./quux
./quux/foo
./quux/foo/bar
./quux/foo/bar/baz
As foo
is ignored, git assumes working directory is clean:
% git status
# On branch master
nothing to commit, working directory clean
The git clean -ndx
prints:
% git clean -ndx
Would remove quux/
But git clean -ndX
doesn't print anything. I would expect it to remove quux/
as well.
Is this a bug or a some gitignore feature I don’t get?
If I add some file to quux
and commit it. Than git clean will try to remove quux/foo/
as expected.
My git is pretty new: git version 1.8.3.4
.
If the Git configuration variable clean. requireForce is not set to false, git clean will refuse to delete files or directories unless given -f or -i. Git will refuse to modify untracked nested git repositories (directories with a . git subdirectory) unless a second -f is given.
Just run the rm command with the -f and -r switch to recursively remove the . git folder and all of the files and folders it contains.
By default, git clean will only remove untracked files that are not ignored. Any file that matches a pattern in your . gitignore or other ignore files will not be removed. If you want to remove those files too, you can add a -x to the clean command.
$ git init .
$ echo foo/ >.gitignore
$ git add .;git commit -am ignore
$ mkdir -p foo/bar bar/foo
$ touch foo/bar/1 bar/foo/1
$ git clean -ndx
Would remove bar/
Would remove foo/
$ git clean -ndX
Would remove foo/
$
git help clean
says:
-X
Remove only files ignored by Git. This may be useful to rebuild
everything from scratch, but keep manually created files.
This means it will not delete manual created stuff, unless it is explicitly ignored.
In this case the bar
directory is manually created and not explicitly ignored, hence it will not be deleted.
The same is true for your quux
directory.
To "fix" this you need to add the bar
directory under control of git by adding a file:
$ touch bar/x
$ git add bar/x
$ git commit -am add\ x
$ git clean -ndX
Would remove bar/foo/
Would remove foo/
$
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