blob: 6bab201d37548dd5c4f911baf981f3fc1995a889 [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 Hamano98137252023-02-27 18:49:3089--mtime=<time>::
90Set modification time of archive entries. Without this option
91the committer time is used if `<tree-ish>` is a commit or tag,
92and the current time if it is a tree.
93
Junio C Hamano781d8a22006-09-17 10:34:1594<extra>::
Junio C Hamanofd83b8e2009-03-22 08:21:4195This can be any options that the archiver backend understands.
Junio C Hamano817abb42006-09-26 07:16:5896See next section.
Junio C Hamano781d8a22006-09-17 10:34:1597
98--remote=<repo>::
Junio C Hamanofd83b8e2009-03-22 08:21:4199Instead of making a tar archive from the local repository,
Junio C Hamano81703b22014-03-14 22:00:27100retrieve a tar archive from a remote repository. Note that the
101remote repository may place restrictions on which sha1
102expressions may be allowed in `<tree-ish>`. See
103linkgit:git-upload-archive[1] for details.
Junio C Hamano781d8a22006-09-17 10:34:15104
Junio C Hamano764a6672007-10-23 01:23:31105--exec=<git-upload-archive>::
106Used with --remote to specify the path to the
Junio C Hamanoba4b9282008-07-06 05:20:31107'git-upload-archive' on the remote side.
Junio C Hamano764a6672007-10-23 01:23:31108
Junio C Hamano781d8a22006-09-17 10:34:15109<tree-ish>::
110The tree or commit to produce an archive for.
111
Junio C Hamanod2179ef2010-10-22 04:12:17112<path>::
Junio C Hamanoe5574b62009-12-06 04:04:45113Without an optional path parameter, all files and subdirectories
114of the current working directory are included in the archive.
115If one or more paths are specified, only these are included.
Junio C Hamano781d8a22006-09-17 10:34:15116
Junio C Hamano817abb42006-09-26 07:16:58117BACKEND EXTRA OPTIONS
118---------------------
119
120zip
121~~~
Junio C Hamano19dcd3f2021-10-29 23:20:47122-<digit>::
123Specify compression level. Larger values allow the command
124to spend more time to compress to smaller size. Supported
125values are from `-0` (store-only) to `-9` (best ratio).
126Default is `-6` if not given.
Junio C Hamano817abb42006-09-26 07:16:58127
Junio C Hamano19dcd3f2021-10-29 23:20:47128tar
129~~~
130-<number>::
131Specify compression level. The value will be passed to the
132compression command configured in `tar.<format>.command`. See
133manual page of the configured command for the list of supported
134levels and the default level if this option isn't specified.
Junio C Hamano817abb42006-09-26 07:16:58135
Junio C Hamano781d8a22006-09-17 10:34:15136CONFIGURATION
137-------------
Junio C Hamano781d8a22006-09-17 10:34:15138
Junio C Hamanobdebabb2007-08-23 00:25:09139tar.umask::
140This variable can be used to restrict the permission bits of
141tar archive entries. The default is 0002, which turns off the
142world write bit. The special value "user" indicates that the
143archiving user's umask will be used instead. See umask(2) for
Junio C Hamanof75a9402011-04-14 23:39:23144details. If `--remote` is used then only the configuration of
145the remote repository takes effect.
Junio C Hamano781d8a22006-09-17 10:34:15146
Junio C Hamano708376e2011-07-19 20:02:13147tar.<format>.command::
148This variable specifies a shell command through which the tar
149output generated by `git archive` should be piped. The command
150is executed using the shell with the generated tar file on its
151standard input, and should produce the final output on its
152standard output. Any compression-level options will be passed
Junio C Hamano7bc73592022-07-11 23:08:34153to the command (e.g., `-9`).
Junio C Hamano708376e2011-07-19 20:02:13154+
Junio C Hamano7bc73592022-07-11 23:08:34155The `tar.gz` and `tgz` formats are defined automatically and use the
156magic command `git archive gzip` by default, which invokes an internal
157implementation of gzip.
Junio C Hamano708376e2011-07-19 20:02:13158
159tar.<format>.remote::
Junio C Hamano7bc73592022-07-11 23:08:34160If true, enable the format for use by remote clients via
Junio C Hamano708376e2011-07-19 20:02:13161linkgit:git-upload-archive[1]. Defaults to false for
Junio C Hamano7bc73592022-07-11 23:08:34162user-defined formats, but true for the `tar.gz` and `tgz`
Junio C Hamano708376e2011-07-19 20:02:13163formats.
164
Junio C Hamano0eb11502013-04-12 02:14:19165[[ATTRIBUTES]]
Junio C Hamanoa9eca4e2009-03-04 08:29:59166ATTRIBUTES
167----------
168
169export-ignore::
170Files and directories with the attribute export-ignore won't be
171added to archive files. See linkgit:gitattributes[5] for details.
172
173export-subst::
Junio C Hamano076ffcc2013-02-06 05:13:21174If the attribute export-subst is set for a file then Git will
Junio C Hamanoa9eca4e2009-03-04 08:29:59175expand several placeholders when adding this file to an archive.
176See linkgit:gitattributes[5] for details.
177
Junio C Hamano1123f302010-02-12 20:51:24178Note that attributes are by default taken from the `.gitattributes` files
179in the tree that is being archived. If you want to tweak the way the
180output is generated after the fact (e.g. you committed without adding an
181appropriate export-ignore in its `.gitattributes`), adjust the checked out
Junio C Hamano81435632011-01-12 09:08:48182`.gitattributes` file as necessary and use `--worktree-attributes`
Junio C Hamano1123f302010-02-12 20:51:24183option. Alternatively you can keep necessary attributes that should apply
184while archiving any tree in your `$GIT_DIR/info/attributes` file.
185
Junio C Hamano781d8a22006-09-17 10:34:15186EXAMPLES
187--------
Junio C Hamano16ebcd02011-08-05 00:05:45188`git archive --format=tar --prefix=junk/ HEAD | (cd /var/tmp/ && tar xf -)`::
Junio C Hamano781d8a22006-09-17 10:34:15189
190Create a tar archive that contains the contents of the
Junio C Hamanofd83b8e2009-03-22 08:21:41191latest commit on the current branch, and extract it in the
Junio C Hamano781d8a22006-09-17 10:34:15192`/var/tmp/junk` directory.
193
Junio C Hamano16ebcd02011-08-05 00:05:45194`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:15195
196Create a compressed tarball for v1.4.0 release.
197
Junio C Hamano16ebcd02011-08-05 00:05:45198`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:13199
200Same as above, but using the builtin tar.gz handling.
201
Junio C Hamano16ebcd02011-08-05 00:05:45202`git archive --prefix=git-1.4.0/ -o git-1.4.0.tar.gz v1.4.0`::
Junio C Hamano708376e2011-07-19 20:02:13203
204Same as above, but the format is inferred from the output file.
205
Junio C Hamanob76a6862012-05-02 22:02:46206`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:15207
208Create a compressed tarball for v1.4.0 release, but without a
209global extended pax header.
210
Junio C Hamano16ebcd02011-08-05 00:05:45211`git archive --format=zip --prefix=git-docs/ HEAD:Documentation/ > git-1.4.0-docs.zip`::
Junio C Hamano781d8a22006-09-17 10:34:15212
213Put everything in the current head's Documentation/ directory
214into 'git-1.4.0-docs.zip', with the prefix 'git-docs/'.
215
Junio C Hamano16ebcd02011-08-05 00:05:45216`git archive -o latest.zip HEAD`::
Junio C Hamanod6fff402009-09-14 09:40:50217
218Create a Zip archive that contains the contents of the latest
219commit on the current branch. Note that the output format is
220inferred by the extension of the output file.
221
Junio C Hamano80b28392022-06-07 21:53:15222`git archive -o latest.tar --prefix=build/ --add-file=configure --prefix= HEAD`::
223
224Creates a tar archive that contains the contents of the latest
225commit on the current branch with no prefix and the untracked
226file 'configure' with the prefix 'build/'.
227
Junio C Hamano16ebcd02011-08-05 00:05:45228`git config tar.tar.xz.command "xz -c"`::
Junio C Hamano708376e2011-07-19 20:02:13229
230Configure a "tar.xz" format for making LZMA-compressed tarfiles.
231You can use it specifying `--format=tar.xz`, or by creating an
232output file like `-o foo.tar.xz`.
233
Junio C Hamanoa9eca4e2009-03-04 08:29:59234
235SEE ALSO
236--------
237linkgit:gitattributes[5]
238
Junio C Hamano781d8a22006-09-17 10:34:15239GIT
240---
Junio C Hamanof7c042d2008-06-06 22:50:53241Part of the linkgit:git[1] suite