void.pointer
void.pointer

Reputation: 26315

git clean isn't cleaning hidden files

I have 3 untracked files in my working directory:

$ git sta
## features/subchecks...upstream/BR_4_1_4 [ahead 4]
?? Applications/ETM/Build/Android/.project
?? Applications/zFacebook/Build/Android/.project
?? Core/Barcode/Build/Android/.project

I do a dry run of git clean like so:

$ git clean -n

But it's not showing any files will be cleaned. Why is it not cleaning the .project files? I'm using msysgit 1.9.2 on Windows.

Upvotes: 4

Views: 6969

Answers (3)

Jeff Scott Brown
Jeff Scott Brown

Reputation: 27200

To put the tree back into a fully clean slate and get rid of everything locally that is not tracked by git, do the following:

git clean -fdx

If you want to keep files that are ignored by git (i.e. files in .gitignore) then leave the "x" off.

Upvotes: 6

void.pointer
void.pointer

Reputation: 26315

Using git clean for this won't work, but the following did work for me and only cleaned what I saw in git status:

$ rm $(git ls-files --others --exclude-standard)

Upvotes: 2

zmo
zmo

Reputation: 24812

it's because you need to add -d to git clean to have it clean directories as well:

% git help clean

OPTIONS
       -d
           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.

Upvotes: 4

Related Questions