7
閱讀.gitignore
幾個問題後,所有文件夾中的某些文件,我發現沒有一個可以回答我的問題:忽略使用單一的.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
如果文件內容/的abc.txt和內容/ def.txt由clean -n -x
顯示,但不clean -n
,我認爲他們將被忽略。但那爲什麼他們不出現在git status --ignored --untracked-files=all
?
看來,之所以因爲'git的狀態--ignored --untracked-文件= all'沒有顯示在您的測試這些文件有事情做與「目錄沒有被跟蹤」(實際上,你可以跟蹤目錄,只是文件,但當我跟蹤他們出現的目錄內的文件) – KurzedMetal
這工作。奇怪的是'git clean -fx'只在文件夾包含一個跟蹤文件後刪除內容中的文件。否則,我不得不在文件夾中調用命令來刪除文件! – Onur