git archive : export-ignore, ignoring directories

I have a git repository with this .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

but when I make:

  • git-bisect but for N repos
  • How to read the mode field of git-ls-tree's output
  • Git push hangs for a large repository
  • How to remove branch from a remote (on Atlassian Stash/Bitbucket)
  • Any project hosting with a in-browser code editor like Google Code?
  • How to modify existing, unpushed commits?
  • git archive HEAD | tar -x -C ../archive_dir
    

    in the archive_dir directory, I get the directories hooks and tests:

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

    Why?

    My git version is 1.7.9.

  • Setting up Laravel project with Git
  • Couldn't merge origin/master: error: Your local changes to the following files would be overwritten by merge
  • How to git stash pop specific stash in 1.8.3?
  • Git recursive mv files
  • Recommend a Git GUI client for Ubuntu 11.10
  • Easier way to keep a git feature branch up to date
  • 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 (pclouds):

    archive: support filtering paths with glob

    This patch fixes two problems with using :(glob) (or even “*.c” without “:(glob)“).

    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”.

    Examples:

    git archive -v HEAD -- ":(glob)**/sh"
    
    git archive -o docs.zip v2.2.0 'Documentation/*.html'
    
    Git Baby is a git and github fan, let's start git clone.