【发布时间】:2015-03-29 13:01:48
【问题描述】:
我想在一个 git 存储库中有两个目录。 我选择的方法是在顶级目录中创建一个 git 存储库,然后使用 .gitignore 将两个感兴趣的目录列入白名单。 要求在我尝试的 .gitignore 文件的 cmets 内:
# Blacklist everything
*
# Whitelist directories of interest and their contents
# stage files in directory A/ recursively
!A/
!A/*
# stage files in directory B/B1/ recursively (without staging files in B/)
!B/B1/
!B/B1/**
# Whitelist files of interest
# stage only the .md files (not .txt files)
!*.md
如何编写将两个目录列入白名单的 .gitignore 文件?
以上gitignore文件基于.gitignore ignoring whitelisted folder
这是我测试 .gitignore 的目录:
$ find A B C
A
A/a.md
A/a.txt
A/A1
A/A1/a1.md
A/A1/a1.txt
B
B/b.md
B/b.txt
B/B1
B/B1/b1.md
B/B1/b1.txt
C
C/c.md
这是我测试 .gitignore 文件的方法:
$ find A B C #list all paths
$ git init
#test .gitignore:
$ git add . --dry-run #show what would be staged
#edit gitignore and test again
预期输出:
$ git add . --dry-run
add 'A/A1/a1.md
add 'A/a.md
add 'B/B1/b1.md
【问题讨论】:
标签: git whitelist subdirectory