tags:

views:

46

answers:

1
git checkout master
git archive stage | tar -czf archive.tar.gz htdocs
# archives master because it's checked out.

How can I archives the stage branch, regardless of the current I'm on?

+5  A: 

git archive creates a tar archive so you don't need to pipe its output tar, indeed it's not doing what you expect. You are creating an tar archive of the stage branch and piping it to a normal tar command which doesn't use its standard input but just creates its own archive of htdocs in the working tree, independently of git.

Try:

git archive stage >stage.tar

or, for a compressed archive:

git archive stage | gzip >stage.tar.gz

To just archive the htdocs subfolder you can do:

git archive stage:htdocs | gzip >stage-htdocs.tar.gz

or, to include the folder name in the archive:

git archive --prefix=htdocs/ stage:htdocs | gzip >stage-htdocs.tar.gz

or more simply:

git archive stage htdocs | gzip >stage-htdocs.tar.gz
Charles Bailey
That last one will archive the root tree of the commit and prefix every pathname with `htdocs/` (e.g. `htdocs/rootfile.c`, `htdocs/sub/file.pl`, and `htdocs/htdocs/htdocfile.html`). It should either specify the tree-ish `stage:htdocs` (to which the prefix is re-added), or you could just use `git archive stage htdocs`.
Chris Johnsen
@Chris Johnsen: Thanks, this was actually a copy I meant it to be a variation of the previous command.
Charles Bailey