# How to archive repo from sub-directory

2 messages from 2008-03-11 to 2008-03-11. Participants: Bill Lear, Nguyen Thai Ngoc Duy.
Thread: https://gitlist.dev/t/12625

## Bill Lear, 2008-03-11 00:33

Subject: How to archive repo from sub-directory
Message-ID: <18389.54080.211086.922039@lisa.zopyra.com>
URL: https://gitlist.dev/e/18389.54080.211086.922039%40lisa.zopyra.com

```
If I have a git repo with several levels of sub-directories, how
do I get git-archive to archive the entire tree, and not just
the tree from where I am?  Example:

% cd foo
% cat .git/description
foo project
% cd bar/baz
% git archive --format=tar --prefix=foo/ HEAD | bzip2 > foo.tar.bz2

produces a tar file starting only at baz.

If I can't conjur this on the command line with a clever argument to
git archive (I've tried several), then how would I ask git "What is
your top-level directory" so at least I could write a script to
do this?


Bill

```

## Nguyen Thai Ngoc Duy, 2008-03-11 03:22

Subject: Re: How to archive repo from sub-directory
Message-ID: <fcaeb9bf0803102022s3cefd1d0jcea74fcf5ac69f6c@mail.gmail.com>
URL: https://gitlist.dev/e/fcaeb9bf0803102022s3cefd1d0jcea74fcf5ac69f6c%40mail.gmail.com
In-Reply-To: <18389.54080.211086.922039@lisa.zopyra.com>

```
On Tue, Mar 11, 2008 at 7:33 AM, Bill Lear <rael@zopyra.com> wrote:
> If I have a git repo with several levels of sub-directories, how
>  do I get git-archive to archive the entire tree, and not just
>  the tree from where I am?  Example:
>
>  % cd foo
>  % cat .git/description
>  foo project
>  % cd bar/baz
>  % git archive --format=tar --prefix=foo/ HEAD | bzip2 > foo.tar.bz2
>
>  produces a tar file starting only at baz.
>
>  If I can't conjur this on the command line with a clever argument to
>  git archive (I've tried several), then how would I ask git "What is
>  your top-level directory" so at least I could write a script to
>  do this?

You can move back to top-level dir with "cd $(git rev-parse
--show-cdup)". Another way is take "git rev-parse --show-prefix"
result (which would be "bar/baz/") and process it yourself.
-- 
Duy

```
