我在 SO 上搜索这个答案,但没有任何相似之处,或者我迷路了。我正在尝试排除特定子文件夹中除一个文件夹之外的所有内容。可能我可以手动完成所有路径,但我认为应该有聪明的方法。我的文件结构:
.gitignore
test/
file1
file2
sim_case/
file1
file2
include/
file1
file2
在 .gitignore 中我有:
**/sim_case
这排除了 sim_case 中的所有内容,但我想包含文件夹“include”。我尝试了一些变体,但没有任何效果。
!**/sim_case/include
!**/sim_case/include/
!**/sim_case/include/*
!sim_case/include/
!sim_case/include/
!sim_case/include/*
最佳答案
我几乎没有做任何研究,看来仅排除“sim_case”文件夹中的文件的最佳选择是使用:
**/sim_case/*
!**/sim_case/include
这允许有更复杂的文件结构
test/sim_case/include
test1/sim_case/include
etc.
“git status”的结果:
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: .gitignore
new file: test/file1
new file: test/file2
new file: test/sim_case/include/file1
new file: test/sim_case/include/file2
new file: test1/file1
new file: test1/file2
new file: test1/sim_case/include/file1
new file: test1/sim_case/include/file2
关于Gitignore 排除子文件夹(带有 **/pattern)除了特定的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35695042/