在阅读了几个关于.gitignore
我的问题后,我发现没有人可以回答我的问题:
我必须添加什么到 .gitignore 以忽略所有具有特定结尾的文件,比如
*.txt
在所有文件夹中。
我宁愿.gitignore
在顶层只有一个文件。
我尝试了几件事,但都没有奏效。
这是我测试的(.gitignore
之前添加到存储库中,没有添加其他文件):
$ ls
abc.txt content
$ ls content/
abc.txt def.other def.txt
$ echo "" > .gitignore
$ git status --ignored --untracked-files=all
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: .gitignore
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# abc.txt
# content/abc.txt
# content/def.other
# content/def.txt
no changes added to commit (use "git add" and/or "git commit -a")
正如预期的那样:所有文件都会显示,因为 .gitignore 是空的。
$ echo "*.txt" > .gitignore
$ git status --ignored --untracked-files=all
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: .gitignore
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# content/def.other
# Ignored files:
# (use "git add -f <file>..." to include in what will be committed)
#
# abc.txt
no changes added to commit (use "git add" and/or "git commit -a")
为什么文件 content/abc.txt 和 content/def.txt 没有出现在列表中?
$ git clean -n
Would not remove content/
我以为他们也会出现在这里。
$ echo "" > .gitignore
$ git clean -n
Would remove abc.txt
Would not remove content/
$ cd content
$ git clean -n -x
Would remove def.other
$ git clean -n -x
Would remove abc.txt
Would remove def.other
Would remove def.txt
如果文件 content/abc.txt 和 content/def.txt 显示为 byclean -n -x
但不是 by clean -n
,我认为它们会被忽略。但是为什么他们不出现git status --ignored --untracked-files=all
呢?