git clean -ndX不会删除目录 [英] git clean -ndX doesn't remove directory

查看:120
本文介绍了git clean -ndX不会删除目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.gitignore :


foo /



和一个git仓库:

  ./ quux 
./quux/foo
./quux/foo/bar
./quux/foo/bar/baz

由于 foo 被忽略,所以git假定工作目录是干净的:

 %git status 
#分支大师
无需提交,工作目录干净

git clean -ndx 列印:

 %git clean -ndx 
会删除quux /

但是 git clean -ndX 不会打印任何内容。我预计它也会删除 quux /



这是一个bug还是一个gitignore功能没有?
如果我将一些文件添加到 quux 并提交它。 git clean会尝试删除 quux / foo / ,如预期那样。 我的git非常新颖: git version 1.8.3.4

解决方案

  $ git init。 
$ echo foo /> .gitignore
$ git add。; git commit -am忽略
$ mkdir -p foo / bar bar / foo
$ touch foo / bar / 1 bar / foo / 1
$ git clean -ndx
将删除bar /
将删除foo /
$ git clean -ndX
将删除foo /
$
$ / code>

git help clean 说:

  -X 
只删除Git忽略的文件。这可能对从头开始重新生成
的所有东西很有用,但保留手动创建的文件。

这意味着它不会删除手动创建的东西,除非明确忽略它。



在这种情况下,手动创建 bar 目录并且不会显式忽略,因此它不会被删除。



对于 quux 目录也是如此。



要修复这需要在git的控制下通过添加一个文件来添加 bar 目录:

  $ touch bar / x 
$ git add bar / x
$ git commit -am add\ x
$ git clean -ndX
将删除bar / foo /
会删除foo /
$


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.

解决方案

$ 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/
$

这篇关于git clean -ndX不会删除目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆