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:

  • How do I upload an SSH key to Visual Studio Team Services (for Git repos)
  • Create a new git repo off of a branch in a directory
  • How can I update the project files using git effectively?
  • How to run Ruby and GIT commands in one place on Windows
  • Git Mess! Commits in the wrong branch
  • Trigger `git prune` automatically on `git pull`?
  • 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.

  • Examining a changeset in HG
  • Git merge master into branch commit ordering
  • TeamCity + git and authentication for submodules
  • Show git pull graph in other situations
  • Git says that some of my image files are untracked (they are not)
  • Homebrew install: Failed during: git fetch origin master:refs/remotes/origin/master -n --depth=1
  • 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.