我想在一个 git 存储库中有两个目录。
我选择的方法是在顶级目录中创建 git 存储库,然后使用 .gitignore 将感兴趣的两个目录列入白名单。
要求位于我尝试的 .gitignore 文件的注释中:
# 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 忽略白名单文件夹 https://stackoverflow.com/questions/25003448/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
此 .gitignore 文件将目录 A 和 B/B1 列入白名单,并排除 .txt 文件:
#exclude files and directories in top directory
/*
#include the A directory
!/A
#include the B directory
!/B
#exclude files and directories in B
/B/*
#include the B/B1 directory
!/B/B1
#ignore .txt files
*.txt
它基于最后一个例子http://git-scm.com/docs/gitignore http://git-scm.com/docs/gitignore
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)