![](/img/trans.png)
[英]Exclude folder in .gitignore but include files starting with a certain prefix
[英].gitignore exclude folder with files but include subdirectory
我有這樣的文件夾:
/foo/one.txt
/foo/bar/two.txt
/foo/other/three.txt
我想排除文件夾/ foo /中的所有內容,除了子文件夾/ foo / bar /。 我怎么做?
有了這個.gitignore,我設法排除了“其他”子文件夾,但文件“one.txt”仍然包括在內。
/foo/*
!/foo/bar/
就像Charles Bailey在評論部分所說,你的代碼有效:
$ cat .gitignore
/foo/*
!/foo/bar/
$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore
# foo/
nothing added to commit but untracked files present (use "git add" to track)
$ git add foo/ -n
add 'foo/bar/two.txt'
$
可能是因為.gitignore
現在正在工作,你遇到了需要從現在位於gitignore的索引中刪除跟蹤文件的常見問題,例如why-git-doesnt-ignore-my-specified-file
也就是說,使用git rm <file>
刪除/確保它不在索引中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.