git archive : export-ignore, ignoring directories
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
but when I make:
git archive HEAD | tar -x -C ../archive_dir
archive_dir directory, I get the directories
ls ../archive_dir/ hooks/ my_script.py tests/
My git version is 1.7.9.
2 Solutions collect form web for “git archive : export-ignore, ignoring directories”
I removed the
/ in the directories, this fixed the problem
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
I find the solution in a answer to a similar question: git ignoring .gitattributes pattern
Another approach, possible since Git 2.2+ (November 2014) is to filter the path you want to include in the archive.
See commit ed22b41 by Nguyễn Thái Ngọc Duy (
archive: support filtering paths with glob
This patch fixes two problems with using :
(glob)(or even “
*.c” without “
The first one is we forgot to turn on the ‘recursive’ flag in
struct pathspec. Without that,
tree_entry_interesting()will not mark potential directories “interesting” so that it can confirm whether those directories have anything matching the pathspec.
The marking directories interesting has a side effect that we need to walk inside a directory to realize that there’s nothing interested in there. By that time, ‘
archive‘ code has already written the (empty) directory down.
That means lots of empty directories in the result archive.
This problem is fixed by lazily writing directories down when we know they are actually needed. There is a theoretical bug in this implementation: we can’t write empty trees/directories that match that pathspec.
path_exists()is also made stricter in order to detect non-matching pathspec because when this ‘recursive’ flag is on, we most likely match some directories. The easiest way is not consider any directories “matched”.
git archive -v HEAD -- ":(glob)**/sh" git archive -o docs.zip v2.2.0 'Documentation/*.html'