为什么git clean不删除特定文件?

时间:2016-12-21 20:19:25

标签: git

我的项目中有一个文件存在于先前的提交中,然后被稍后的提交删除。我想使用git clean删除文件,但它不会这样做。我使用了rm文件的解决方法,但我想知道:

为什么git clean不会将此文件视为删除的候选对象?

这是我实验的(消毒过的)痕迹:

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

1 个答案:

答案 0 :(得分:2)

help for git clean说&#34;通过递归删除不受版本控制的文件来清理工作树,从当前目录开始。&#34; (强调我的)

因此,由于文件位于../app,因此在命令尝试删除之前,您需要上升一级。