git archive:export-ignore,忽略目录

时间:2014-02-17 14:51:35

标签: git gitattributes git-archive

我有一个带有.gitattributes的git存储库:

my_script.py export-subst
Makefile export-ignore
README.md export-ignore
.gitattributes export-ignore
.gitignore export-ignore
hooks/ export-ignore
tests/ export-ignore
*.pyc export-ignore

但是当我做的时候:

git archive HEAD | tar -x -C ../archive_dir

archive_dir目录中,我获取了目录hookstests

 ls ../archive_dir/
 hooks/  my_script.py tests/

为什么?

我的git版本是1.7.9。

2 个答案:

答案 0 :(得分:9)

我删除了目录中的/,这解决了问题

my_script.py export-subst
Makefile export-ignore
README.md export-ignore
.gitattributes export-ignore
.gitignore export-ignore
hooks export-ignore
tests export-ignore
*.pyc export-ignore

我在回答类似问题时找到了解决方案:git ignoring .gitattributes pattern

答案 1 :(得分:2)

自Git 2.2 +(2014年11月)以来,另一种方法是过滤您希望包含在档案中的路径

commit ed22b41Nguyễn Thái Ngọc Duy (pclouds)

archive:支持使用glob

过滤路径
  

此修补程序修复了使用时遇到的两个问题:(glob)(甚至“*.c”没有“:(glob)”。

     

第一个是我们忘记打开struct pathspec中的'递归'标志。如果没有这个,tree_entry_interesting()将不会将潜在目录标记为“有趣”,以便它可以确认这些目录是否具有与pathspec匹配的任何内容。

     

有趣的标记目录有副作用,我们需要走进一个目录才能意识到那里没什么兴趣。到那时,“archive”代码已经写下了(空)目录   这意味着结果存档中有很多空目录。

     

当我们知道实际需要时,懒洋洋地写下目录可以解决这个问题。这个实现中存在一个理论上的错误:我们不能编写与那个pathspec匹配的空树/目录。

     为了检测不匹配的pathspec,

path_exists()也变得更加严格,因为当这个'recursive'标志打开时,我们很可能匹配某些目录。最简单的方法是不考虑任何“匹配”的目录。

示例:

git archive -v HEAD -- ":(glob)**/sh"

git archive -o docs.zip v2.2.0 'Documentation/*.html'
相关问题