blob: 56989a2f3493aa80530cb9efc72e74ba8d42eb56 [file] [log] [blame]
Junio C Hamano781d8a22006-09-17 10:34:151git-archive(1)
2==============
3
4NAME
5----
Junio C Hamano4ec06712007-06-09 20:39:336git-archive - Create an archive of files from a named tree
Junio C Hamano781d8a22006-09-17 10:34:157
8
9SYNOPSIS
10--------
Junio C Hamanoa9b8d242007-05-19 04:51:5511[verse]
Junio C Hamanoe367f7b2009-08-28 09:18:2812'git archive' [--format=<fmt>] [--list] [--prefix=<prefix>/] [<extra>]
Junio C Hamano3d1b5a12013-05-17 23:34:0213 [-o <file> | --output=<file>] [--worktree-attributes]
Junio C Hamano764a6672007-10-23 01:23:3114 [--remote=<repo> [--exec=<git-upload-archive>]] <tree-ish>
Junio C Hamanod2179ef2010-10-22 04:12:1715 [<path>...]
Junio C Hamano781d8a22006-09-17 10:34:1516
17DESCRIPTION
18-----------
19Creates an archive of the specified format containing the tree
Junio C Hamano58155b42007-09-15 07:46:1420structure for the named tree, and writes it out to the standard
21output. If <prefix> is specified it is
Junio C Hamano781d8a22006-09-17 10:34:1522prepended to the filenames in the archive.
23
Junio C Hamano1aa40d22010-01-21 17:46:4324'git archive' behaves differently when given a tree ID versus when
Junio C Hamano781d8a22006-09-17 10:34:1525given a commit ID or tag ID. In the first case the current time is
Junio C Hamanofd83b8e2009-03-22 08:21:4126used as the modification time of each file in the archive. In the latter
Junio C Hamano781d8a22006-09-17 10:34:1527case the commit time as recorded in the referenced commit object is
28used instead. Additionally the commit ID is stored in a global
29extended pax header if the tar format is used; it can be extracted
Junio C Hamano1aa40d22010-01-21 17:46:4330using 'git get-tar-commit-id'. In ZIP files it is stored as a file
Junio C Hamano781d8a22006-09-17 10:34:1531comment.
32
33OPTIONS
34-------
35
36--format=<fmt>::
Junio C Hamanod6fff402009-09-14 09:40:5037Format of the resulting archive: 'tar' or 'zip'. If this option
38is not given, and the output file is specified, the format is
39inferred from the filename if possible (e.g. writing to "foo.zip"
40makes the output to be in the zip format). Otherwise the output
41format is `tar`.
Junio C Hamano781d8a22006-09-17 10:34:1542
Junio C Hamanoeb415992008-06-08 22:49:4743-l::
44--list::
Junio C Hamano781d8a22006-09-17 10:34:1545Show all available formats.
46
Junio C Hamanoeb415992008-06-08 22:49:4747-v::
48--verbose::
Junio C Hamano81c711d2007-04-20 07:20:1449Report progress to stderr.
50
Junio C Hamano781d8a22006-09-17 10:34:1551--prefix=<prefix>/::
Junio C Hamano80b28392022-06-07 21:53:1552Prepend <prefix>/ to paths in the archive. Can be repeated; its
53rightmost value is used for all tracked files. See below which
54value gets used by `--add-file` and `--add-virtual-file`.
Junio C Hamano781d8a22006-09-17 10:34:1555
Junio C Hamanod6fff402009-09-14 09:40:5056-o <file>::
Junio C Hamano36ac9932009-03-05 09:57:1057--output=<file>::
58Write the archive to <file> instead of stdout.
59
Junio C Hamanod1281512020-10-05 22:21:5560--add-file=<file>::
61Add a non-tracked file to the archive. Can be repeated to add
Junio C Hamano80b28392022-06-07 21:53:1562multiple files. The path of the file in the archive is built by
63concatenating the value of the last `--prefix` option (if any)
64before this `--add-file` and the basename of <file>.
65
66--add-virtual-file=<path>:<content>::
67Add the specified contents to the archive. Can be repeated to add
Junio C Hamanod1281512020-10-05 22:21:5568multiple files. The path of the file in the archive is built
Junio C Hamano80b28392022-06-07 21:53:1569by concatenating the value of the last `--prefix` option (if any)
70before this `--add-virtual-file` and `<path>`.
71+
72The `<path>` argument can start and end with a literal double-quote
73character; the contained file name is interpreted as a C-style string,
74i.e. the backslash is interpreted as escape character. The path must
75be quoted if it contains a colon, to avoid the colon from being
76misinterpreted as the separator between the path and the contents, or
77if the path begins or ends with a double-quote character.
78+
79The file mode is limited to a regular file, and the option may be
80subject to platform-dependent command-line limits. For non-trivial
81cases, write an untracked file and use `--add-file` instead.
Junio C Hamanod1281512020-10-05 22:21:5582
Junio C Hamano4cfa5362009-04-18 23:01:0183--worktree-attributes::
Junio C Hamano0eb11502013-04-12 02:14:1984Look for attributes in .gitattributes files in the working tree
85as well (see <<ATTRIBUTES>>).
Junio C Hamano4cfa5362009-04-18 23:01:0186
Junio C Hamano781d8a22006-09-17 10:34:1587<extra>::
Junio C Hamanofd83b8e2009-03-22 08:21:4188This can be any options that the archiver backend understands.
Junio C Hamano817abb42006-09-26 07:16:5889See next section.
Junio C Hamano781d8a22006-09-17 10:34:1590
91--remote=<repo>::
Junio C Hamanofd83b8e2009-03-22 08:21:4192Instead of making a tar archive from the local repository,
Junio C Hamano81703b22014-03-14 22:00:2793retrieve a tar archive from a remote repository. Note that the
94remote repository may place restrictions on which sha1
95expressions may be allowed in `<tree-ish>`. See
96linkgit:git-upload-archive[1] for details.
Junio C Hamano781d8a22006-09-17 10:34:1597
Junio C Hamano764a6672007-10-23 01:23:3198--exec=<git-upload-archive>::
99Used with --remote to specify the path to the
Junio C Hamanoba4b9282008-07-06 05:20:31100'git-upload-archive' on the remote side.
Junio C Hamano764a6672007-10-23 01:23:31101
Junio C Hamano781d8a22006-09-17 10:34:15102<tree-ish>::
103The tree or commit to produce an archive for.
104
Junio C Hamanod2179ef2010-10-22 04:12:17105<path>::
Junio C Hamanoe5574b62009-12-06 04:04:45106Without an optional path parameter, all files and subdirectories
107of the current working directory are included in the archive.
108If one or more paths are specified, only these are included.
Junio C Hamano781d8a22006-09-17 10:34:15109
Junio C Hamano817abb42006-09-26 07:16:58110BACKEND EXTRA OPTIONS
111---------------------
112
113zip
114~~~
Junio C Hamano19dcd3f2021-10-29 23:20:47115-<digit>::
116Specify compression level. Larger values allow the command
117to spend more time to compress to smaller size. Supported
118values are from `-0` (store-only) to `-9` (best ratio).
119Default is `-6` if not given.
Junio C Hamano817abb42006-09-26 07:16:58120
Junio C Hamano19dcd3f2021-10-29 23:20:47121tar
122~~~
123-<number>::
124Specify compression level. The value will be passed to the
125compression command configured in `tar.<format>.command`. See
126manual page of the configured command for the list of supported
127levels and the default level if this option isn't specified.
Junio C Hamano817abb42006-09-26 07:16:58128
Junio C Hamano781d8a22006-09-17 10:34:15129CONFIGURATION
130-------------
Junio C Hamano781d8a22006-09-17 10:34:15131
Junio C Hamanobdebabb2007-08-23 00:25:09132tar.umask::
133This variable can be used to restrict the permission bits of
134tar archive entries. The default is 0002, which turns off the
135world write bit. The special value "user" indicates that the
136archiving user's umask will be used instead. See umask(2) for
Junio C Hamanof75a9402011-04-14 23:39:23137details. If `--remote` is used then only the configuration of
138the remote repository takes effect.
Junio C Hamano781d8a22006-09-17 10:34:15139
Junio C Hamano708376e2011-07-19 20:02:13140tar.<format>.command::
141This variable specifies a shell command through which the tar
142output generated by `git archive` should be piped. The command
143is executed using the shell with the generated tar file on its
144standard input, and should produce the final output on its
145standard output. Any compression-level options will be passed
146to the command (e.g., "-9"). An output file with the same
147extension as `<format>` will be use this format if no other
148format is given.
149+
150The "tar.gz" and "tgz" formats are defined automatically and default to
151`gzip -cn`. You may override them with custom commands.
152
153tar.<format>.remote::
154If true, enable `<format>` for use by remote clients via
155linkgit:git-upload-archive[1]. Defaults to false for
156user-defined formats, but true for the "tar.gz" and "tgz"
157formats.
158
Junio C Hamano0eb11502013-04-12 02:14:19159[[ATTRIBUTES]]
Junio C Hamanoa9eca4e2009-03-04 08:29:59160ATTRIBUTES
161----------
162
163export-ignore::
164Files and directories with the attribute export-ignore won't be
165added to archive files. See linkgit:gitattributes[5] for details.
166
167export-subst::
Junio C Hamano076ffcc2013-02-06 05:13:21168If the attribute export-subst is set for a file then Git will
Junio C Hamanoa9eca4e2009-03-04 08:29:59169expand several placeholders when adding this file to an archive.
170See linkgit:gitattributes[5] for details.
171
Junio C Hamano1123f302010-02-12 20:51:24172Note that attributes are by default taken from the `.gitattributes` files
173in the tree that is being archived. If you want to tweak the way the
174output is generated after the fact (e.g. you committed without adding an
175appropriate export-ignore in its `.gitattributes`), adjust the checked out
Junio C Hamano81435632011-01-12 09:08:48176`.gitattributes` file as necessary and use `--worktree-attributes`
Junio C Hamano1123f302010-02-12 20:51:24177option. Alternatively you can keep necessary attributes that should apply
178while archiving any tree in your `$GIT_DIR/info/attributes` file.
179
Junio C Hamano781d8a22006-09-17 10:34:15180EXAMPLES
181--------
Junio C Hamano16ebcd02011-08-05 00:05:45182`git archive --format=tar --prefix=junk/ HEAD | (cd /var/tmp/ && tar xf -)`::
Junio C Hamano781d8a22006-09-17 10:34:15183
184Create a tar archive that contains the contents of the
Junio C Hamanofd83b8e2009-03-22 08:21:41185latest commit on the current branch, and extract it in the
Junio C Hamano781d8a22006-09-17 10:34:15186`/var/tmp/junk` directory.
187
Junio C Hamano16ebcd02011-08-05 00:05:45188`git archive --format=tar --prefix=git-1.4.0/ v1.4.0 | gzip >git-1.4.0.tar.gz`::
Junio C Hamano781d8a22006-09-17 10:34:15189
190Create a compressed tarball for v1.4.0 release.
191
Junio C Hamano16ebcd02011-08-05 00:05:45192`git archive --format=tar.gz --prefix=git-1.4.0/ v1.4.0 >git-1.4.0.tar.gz`::
Junio C Hamano708376e2011-07-19 20:02:13193
194Same as above, but using the builtin tar.gz handling.
195
Junio C Hamano16ebcd02011-08-05 00:05:45196`git archive --prefix=git-1.4.0/ -o git-1.4.0.tar.gz v1.4.0`::
Junio C Hamano708376e2011-07-19 20:02:13197
198Same as above, but the format is inferred from the output file.
199
Junio C Hamanob76a6862012-05-02 22:02:46200`git archive --format=tar --prefix=git-1.4.0/ v1.4.0^{tree} | gzip >git-1.4.0.tar.gz`::
Junio C Hamano781d8a22006-09-17 10:34:15201
202Create a compressed tarball for v1.4.0 release, but without a
203global extended pax header.
204
Junio C Hamano16ebcd02011-08-05 00:05:45205`git archive --format=zip --prefix=git-docs/ HEAD:Documentation/ > git-1.4.0-docs.zip`::
Junio C Hamano781d8a22006-09-17 10:34:15206
207Put everything in the current head's Documentation/ directory
208into 'git-1.4.0-docs.zip', with the prefix 'git-docs/'.
209
Junio C Hamano16ebcd02011-08-05 00:05:45210`git archive -o latest.zip HEAD`::
Junio C Hamanod6fff402009-09-14 09:40:50211
212Create a Zip archive that contains the contents of the latest
213commit on the current branch. Note that the output format is
214inferred by the extension of the output file.
215
Junio C Hamano80b28392022-06-07 21:53:15216`git archive -o latest.tar --prefix=build/ --add-file=configure --prefix= HEAD`::
217
218Creates a tar archive that contains the contents of the latest
219commit on the current branch with no prefix and the untracked
220file 'configure' with the prefix 'build/'.
221
Junio C Hamano16ebcd02011-08-05 00:05:45222`git config tar.tar.xz.command "xz -c"`::
Junio C Hamano708376e2011-07-19 20:02:13223
224Configure a "tar.xz" format for making LZMA-compressed tarfiles.
225You can use it specifying `--format=tar.xz`, or by creating an
226output file like `-o foo.tar.xz`.
227
Junio C Hamanoa9eca4e2009-03-04 08:29:59228
229SEE ALSO
230--------
231linkgit:gitattributes[5]
232
Junio C Hamano781d8a22006-09-17 10:34:15233GIT
234---
Junio C Hamanof7c042d2008-06-06 22:50:53235Part of the linkgit:git[1] suite