git归档:导出忽略,忽略目录

git归档:导出忽略,忽略目录,git,gitattributes,git-archive,Git,Gitattributes,Git Archive,我有一个带有以下内容的git存储库。gitattributes: 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 HEA

我有一个带有以下内容的git存储库
。gitattributes

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\u dir
目录中,我得到了目录
hooks
tests

 ls ../archive_dir/
 hooks/  my_script.py tests/
为什么?


我的git版本是1.7.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 2.2+(2014年11月)是过滤要包含在存档中的路径

见:

存档
:支持使用glob筛选路径 此修补程序修复了使用时出现的两个问题:
(glob)
(甚至是不带“
:(glob)
”的“
*.c

第一个是我们忘记在
struct pathspec
中打开“recursive”标志。如果没有这个选项,
tree\u entry\u interest()

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

当我们知道确实需要目录时,通过懒洋洋地写下它们来解决这个问题。在这个实现中有一个理论上的缺陷:我们不能编写与该pathspec匹配的空树/目录

path\u exists()。最简单的方法是不考虑任何目录“匹配”。
示例:

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

git archive -o docs.zip v2.2.0 'Documentation/*.html'

注意(7年后),同样的命令正在用Git2.32(2021年第2季度)进行重构 参见,,,,(2021年3月20日)by.
(于2021年3月30日合并)

例如,引用上述提交:

:停止通过
read\u tree\u recursive()传递“stage”
签字人:Ævar ArnfjörðBjarmason

存档代码中传递的“
stage
”变量只是对值“0”进行硬编码的一种精心设计的方式

此代码是在(“Add
git zip tree
”,2006-08-26,git v1.4.3-rc1--)中以其原始形式添加的,此时硬编码的“0”将通过
read\u tree\u recursive()
传递到
write\u zip\u entry()

然后,它被勤奋地添加到“
struct目录”
”(“
archive
:support-filtering path with glob)”,2014-09-21,Git v2.2.0-rc0--),但我们仍然没有做任何事情,只是照样传递它

让我们停止在的内部代码中这样做,我们仍然会将“0”馈送到
read\u tree\u recursive()
本身,但不会使用它


@twalberg git版本:1.7。9@twalberg,git export忽略其他文件,仅与目录有问题请注意,您排除了树下的所有
钩子
文件夹。要仅排除根中的一个,请在其前面加上斜杠:
/hooks