Phrogz
Phrogz

Reputation: 303510

Why is git clean is not removing a specific file?

I have a file in my project that was present in previous commits, and then was removed by a later commit. I wanted to use git clean to remove the file, but it wouldn't do it. I used the workaround of just rming the file, but I'm wondering:

Why would git clean not see this file as a candidate for deletion?


Here's the (sanitized) trace of my experiments:

me@mybox:/myproj/build$ git reset --hard origin/master
HEAD is now at 64a87ed Merge branch 'dev/phrogz/whee' into 'master'

me@mybox:/myproj/build$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    ../app/faux/prep.sh

nothing added to commit but untracked files present (use "git add" to track)

me@mybox:/myproj/build$ git clean -n
me@mybox:/myproj/build$ git clean -f -d
me@mybox:/myproj/build$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    ../app/faux/prep.sh

nothing added to commit but untracked files present (use "git add" to track)

me@mybox:/myproj/build$ rm ../app/faux/prep.sh 
me@mybox:/myproj/build$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean

Upvotes: 3

Views: 1407

Answers (1)

Matthew Strawbridge
Matthew Strawbridge

Reputation: 20640

The help for git clean says "Cleans the working tree by recursively removing files that are not under version control, starting from the current directory." (emphasis mine)

So since the file is in ../app you need to go up one level before the command will try to remove it.

Upvotes: 2

Related Questions