blob: 60c040988bb803cbca608b9e58647b75a75ac173 [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 Hamano7bc73592022-07-11 23:08:3437Format of the resulting archive. Possible values are `tar`,
38`zip`, `tar.gz`, `tgz`, and any format defined using the
39configuration option `tar.<format>.command`. If `--format`
Junio C Hamanod6fff402009-09-14 09:40:5040is not given, and the output file is specified, the format is
Junio C Hamano7bc73592022-07-11 23:08:3441inferred from the filename if possible (e.g. writing to `foo.zip`
42makes the output to be in the `zip` format). Otherwise the output
Junio C Hamanod6fff402009-09-14 09:40:5043format is `tar`.
Junio C Hamano781d8a22006-09-17 10:34:1544
Junio C Hamanoeb415992008-06-08 22:49:4745-l::
46--list::
Junio C Hamano781d8a22006-09-17 10:34:1547Show all available formats.
48
Junio C Hamanoeb415992008-06-08 22:49:4749-v::
50--verbose::
Junio C Hamano81c711d2007-04-20 07:20:1451Report progress to stderr.
52
Junio C Hamano781d8a22006-09-17 10:34:1553--prefix=<prefix>/::
Junio C Hamano80b28392022-06-07 21:53:1554Prepend <prefix>/ to paths in the archive. Can be repeated; its
55rightmost value is used for all tracked files. See below which
56value gets used by `--add-file` and `--add-virtual-file`.
Junio C Hamano781d8a22006-09-17 10:34:1557
Junio C Hamanod6fff402009-09-14 09:40:5058-o <file>::
Junio C Hamano36ac9932009-03-05 09:57:1059--output=<file>::
60Write the archive to <file> instead of stdout.
61
Junio C Hamanod1281512020-10-05 22:21:5562--add-file=<file>::
63Add a non-tracked file to the archive. Can be repeated to add
Junio C Hamano80b28392022-06-07 21:53:1564multiple files. The path of the file in the archive is built by
65concatenating the value of the last `--prefix` option (if any)
66before this `--add-file` and the basename of <file>.
67
68--add-virtual-file=<path>:<content>::
69Add the specified contents to the archive. Can be repeated to add
Junio C Hamanod1281512020-10-05 22:21:5570multiple files. The path of the file in the archive is built
Junio C Hamano80b28392022-06-07 21:53:1571by concatenating the value of the last `--prefix` option (if any)
72before this `--add-virtual-file` and `<path>`.
73+
74The `<path>` argument can start and end with a literal double-quote
75character; the contained file name is interpreted as a C-style string,
76i.e. the backslash is interpreted as escape character. The path must
77be quoted if it contains a colon, to avoid the colon from being
78misinterpreted as the separator between the path and the contents, or
79if the path begins or ends with a double-quote character.
80+
81The file mode is limited to a regular file, and the option may be
82subject to platform-dependent command-line limits. For non-trivial
83cases, write an untracked file and use `--add-file` instead.
Junio C Hamanod1281512020-10-05 22:21:5584
Junio C Hamano4cfa5362009-04-18 23:01:0185--worktree-attributes::
Junio C Hamano0eb11502013-04-12 02:14:1986Look for attributes in .gitattributes files in the working tree
87as well (see <<ATTRIBUTES>>).
Junio C Hamano4cfa5362009-04-18 23:01:0188
Junio C Hamano781d8a22006-09-17 10:34:1589<extra>::
Junio C Hamanofd83b8e2009-03-22 08:21:4190This can be any options that the archiver backend understands.
Junio C Hamano817abb42006-09-26 07:16:5891See next section.
Junio C Hamano781d8a22006-09-17 10:34:1592
93--remote=<repo>::
Junio C Hamanofd83b8e2009-03-22 08:21:4194Instead of making a tar archive from the local repository,
Junio C Hamano81703b22014-03-14 22:00:2795retrieve a tar archive from a remote repository. Note that the
96remote repository may place restrictions on which sha1
97expressions may be allowed in `<tree-ish>`. See
98linkgit:git-upload-archive[1] for details.
Junio C Hamano781d8a22006-09-17 10:34:1599
Junio C Hamano764a6672007-10-23 01:23:31100--exec=<git-upload-archive>::
101Used with --remote to specify the path to the
Junio C Hamanoba4b9282008-07-06 05:20:31102'git-upload-archive' on the remote side.
Junio C Hamano764a6672007-10-23 01:23:31103
Junio C Hamano781d8a22006-09-17 10:34:15104<tree-ish>::
105The tree or commit to produce an archive for.
106
Junio C Hamanod2179ef2010-10-22 04:12:17107<path>::
Junio C Hamanoe5574b62009-12-06 04:04:45108Without an optional path parameter, all files and subdirectories
109of the current working directory are included in the archive.
110If one or more paths are specified, only these are included.
Junio C Hamano781d8a22006-09-17 10:34:15111
Junio C Hamano817abb42006-09-26 07:16:58112BACKEND EXTRA OPTIONS
113---------------------
114
115zip
116~~~
Junio C Hamano19dcd3f2021-10-29 23:20:47117-<digit>::
118Specify compression level. Larger values allow the command
119to spend more time to compress to smaller size. Supported
120values are from `-0` (store-only) to `-9` (best ratio).
121Default is `-6` if not given.
Junio C Hamano817abb42006-09-26 07:16:58122
Junio C Hamano19dcd3f2021-10-29 23:20:47123tar
124~~~
125-<number>::
126Specify compression level. The value will be passed to the
127compression command configured in `tar.<format>.command`. See
128manual page of the configured command for the list of supported
129levels and the default level if this option isn't specified.
Junio C Hamano817abb42006-09-26 07:16:58130
Junio C Hamano781d8a22006-09-17 10:34:15131CONFIGURATION
132-------------
Junio C Hamano781d8a22006-09-17 10:34:15133
Junio C Hamanobdebabb2007-08-23 00:25:09134tar.umask::
135This variable can be used to restrict the permission bits of
136tar archive entries. The default is 0002, which turns off the
137world write bit. The special value "user" indicates that the
138archiving user's umask will be used instead. See umask(2) for
Junio C Hamanof75a9402011-04-14 23:39:23139details. If `--remote` is used then only the configuration of
140the remote repository takes effect.
Junio C Hamano781d8a22006-09-17 10:34:15141
Junio C Hamano708376e2011-07-19 20:02:13142tar.<format>.command::
143This variable specifies a shell command through which the tar
144output generated by `git archive` should be piped. The command
145is executed using the shell with the generated tar file on its
146standard input, and should produce the final output on its
147standard output. Any compression-level options will be passed
Junio C Hamano7bc73592022-07-11 23:08:34148to the command (e.g., `-9`).
Junio C Hamano708376e2011-07-19 20:02:13149+
Junio C Hamano7bc73592022-07-11 23:08:34150The `tar.gz` and `tgz` formats are defined automatically and use the
151magic command `git archive gzip` by default, which invokes an internal
152implementation of gzip.
Junio C Hamano708376e2011-07-19 20:02:13153
154tar.<format>.remote::
Junio C Hamano7bc73592022-07-11 23:08:34155If true, enable the format for use by remote clients via
Junio C Hamano708376e2011-07-19 20:02:13156linkgit:git-upload-archive[1]. Defaults to false for
Junio C Hamano7bc73592022-07-11 23:08:34157user-defined formats, but true for the `tar.gz` and `tgz`
Junio C Hamano708376e2011-07-19 20:02:13158formats.
159
Junio C Hamano0eb11502013-04-12 02:14:19160[[ATTRIBUTES]]
Junio C Hamanoa9eca4e2009-03-04 08:29:59161ATTRIBUTES
162----------
163
164export-ignore::
165Files and directories with the attribute export-ignore won't be
166added to archive files. See linkgit:gitattributes[5] for details.
167
168export-subst::
Junio C Hamano076ffcc2013-02-06 05:13:21169If the attribute export-subst is set for a file then Git will
Junio C Hamanoa9eca4e2009-03-04 08:29:59170expand several placeholders when adding this file to an archive.
171See linkgit:gitattributes[5] for details.
172
Junio C Hamano1123f302010-02-12 20:51:24173Note that attributes are by default taken from the `.gitattributes` files
174in the tree that is being archived. If you want to tweak the way the
175output is generated after the fact (e.g. you committed without adding an
176appropriate export-ignore in its `.gitattributes`), adjust the checked out
Junio C Hamano81435632011-01-12 09:08:48177`.gitattributes` file as necessary and use `--worktree-attributes`
Junio C Hamano1123f302010-02-12 20:51:24178option. Alternatively you can keep necessary attributes that should apply
179while archiving any tree in your `$GIT_DIR/info/attributes` file.
180
Junio C Hamano781d8a22006-09-17 10:34:15181EXAMPLES
182--------
Junio C Hamano16ebcd02011-08-05 00:05:45183`git archive --format=tar --prefix=junk/ HEAD | (cd /var/tmp/ && tar xf -)`::
Junio C Hamano781d8a22006-09-17 10:34:15184
185Create a tar archive that contains the contents of the
Junio C Hamanofd83b8e2009-03-22 08:21:41186latest commit on the current branch, and extract it in the
Junio C Hamano781d8a22006-09-17 10:34:15187`/var/tmp/junk` directory.
188
Junio C Hamano16ebcd02011-08-05 00:05:45189`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:15190
191Create a compressed tarball for v1.4.0 release.
192
Junio C Hamano16ebcd02011-08-05 00:05:45193`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:13194
195Same as above, but using the builtin tar.gz handling.
196
Junio C Hamano16ebcd02011-08-05 00:05:45197`git archive --prefix=git-1.4.0/ -o git-1.4.0.tar.gz v1.4.0`::
Junio C Hamano708376e2011-07-19 20:02:13198
199Same as above, but the format is inferred from the output file.
200
Junio C Hamanob76a6862012-05-02 22:02:46201`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:15202
203Create a compressed tarball for v1.4.0 release, but without a
204global extended pax header.
205
Junio C Hamano16ebcd02011-08-05 00:05:45206`git archive --format=zip --prefix=git-docs/ HEAD:Documentation/ > git-1.4.0-docs.zip`::
Junio C Hamano781d8a22006-09-17 10:34:15207
208Put everything in the current head's Documentation/ directory
209into 'git-1.4.0-docs.zip', with the prefix 'git-docs/'.
210
Junio C Hamano16ebcd02011-08-05 00:05:45211`git archive -o latest.zip HEAD`::
Junio C Hamanod6fff402009-09-14 09:40:50212
213Create a Zip archive that contains the contents of the latest
214commit on the current branch. Note that the output format is
215inferred by the extension of the output file.
216
Junio C Hamano80b28392022-06-07 21:53:15217`git archive -o latest.tar --prefix=build/ --add-file=configure --prefix= HEAD`::
218
219Creates a tar archive that contains the contents of the latest
220commit on the current branch with no prefix and the untracked
221file 'configure' with the prefix 'build/'.
222
Junio C Hamano16ebcd02011-08-05 00:05:45223`git config tar.tar.xz.command "xz -c"`::
Junio C Hamano708376e2011-07-19 20:02:13224
225Configure a "tar.xz" format for making LZMA-compressed tarfiles.
226You can use it specifying `--format=tar.xz`, or by creating an
227output file like `-o foo.tar.xz`.
228
Junio C Hamanoa9eca4e2009-03-04 08:29:59229
230SEE ALSO
231--------
232linkgit:gitattributes[5]
233
Junio C Hamano781d8a22006-09-17 10:34:15234GIT
235---
Junio C Hamanof7c042d2008-06-06 22:50:53236Part of the linkgit:git[1] suite