]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-archive.txt
archive --add-virtual-file: allow paths containing colons
[thirdparty/git.git] / Documentation / git-archive.txt
CommitLineData
4df096a5
FBH
1git-archive(1)
2==============
3
4NAME
5----
29cf5e12 6git-archive - Create an archive of files from a named tree
4df096a5
FBH
7
8
9SYNOPSIS
10--------
e448ff87 11[verse]
82d97da3 12'git archive' [--format=<fmt>] [--list] [--prefix=<prefix>/] [<extra>]
0460ed2c 13 [-o <file> | --output=<file>] [--worktree-attributes]
c005c6aa 14 [--remote=<repo> [--exec=<git-upload-archive>]] <tree-ish>
62b4698e 15 [<path>...]
4df096a5
FBH
16
17DESCRIPTION
18-----------
19Creates an archive of the specified format containing the tree
42b5f869
JA
20structure for the named tree, and writes it out to the standard
21output. If <prefix> is specified it is
4df096a5
FBH
22prepended to the filenames in the archive.
23
0b444cdb 24'git archive' behaves differently when given a tree ID versus when
4df096a5 25given a commit ID or tag ID. In the first case the current time is
3f7cdf32 26used as the modification time of each file in the archive. In the latter
4df096a5
FBH
27case 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
0b444cdb 30using 'git get-tar-commit-id'. In ZIP files it is stored as a file
4df096a5
FBH
31comment.
32
33OPTIONS
34-------
35
36--format=<fmt>::
0f4b377c
DP
37 Format of the resulting archive: 'tar' or 'zip'. If this option
38 is not given, and the output file is specified, the format is
39 inferred from the filename if possible (e.g. writing to "foo.zip"
40 makes the output to be in the zip format). Otherwise the output
41 format is `tar`.
4df096a5 42
3240240f
SB
43-l::
44--list::
4df096a5
FBH
45 Show all available formats.
46
3240240f
SB
47-v::
48--verbose::
27c8f8cd
AR
49 Report progress to stderr.
50
4df096a5 51--prefix=<prefix>/::
a7591060
RS
52 Prepend <prefix>/ to paths in the archive. Can be repeated; its
53 rightmost value is used for all tracked files. See below which
237a1d13 54 value gets used by `--add-file` and `--add-virtual-file`.
4df096a5 55
05d3951e 56-o <file>::
aec0c1bb
CMDV
57--output=<file>::
58 Write the archive to <file> instead of stdout.
59
2947a793
RS
60--add-file=<file>::
61 Add a non-tracked file to the archive. Can be repeated to add
a7591060
RS
62 multiple files. The path of the file in the archive is built by
63 concatenating the value of the last `--prefix` option (if any)
64 before this `--add-file` and the basename of <file>.
2947a793 65
237a1d13
JS
66--add-virtual-file=<path>:<content>::
67 Add the specified contents to the archive. Can be repeated to add
68 multiple files. The path of the file in the archive is built
69 by concatenating the value of the last `--prefix` option (if any)
70 before this `--add-virtual-file` and `<path>`.
71+
de1f68a9
JS
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.
237a1d13 82
ba053ea9 83--worktree-attributes::
59a7714c
RS
84 Look for attributes in .gitattributes files in the working tree
85 as well (see <<ATTRIBUTES>>).
ba053ea9 86
4df096a5 87<extra>::
3f7cdf32 88 This can be any options that the archiver backend understands.
e8daf78a 89 See next section.
4df096a5
FBH
90
91--remote=<repo>::
3f7cdf32 92 Instead of making a tar archive from the local repository,
69897bc2
JK
93 retrieve a tar archive from a remote repository. Note that the
94 remote repository may place restrictions on which sha1
95 expressions may be allowed in `<tree-ish>`. See
96 linkgit:git-upload-archive[1] for details.
4df096a5 97
c005c6aa
MB
98--exec=<git-upload-archive>::
99 Used with --remote to specify the path to the
ba020ef5 100 'git-upload-archive' on the remote side.
c005c6aa 101
4df096a5
FBH
102<tree-ish>::
103 The tree or commit to produce an archive for.
104
62b4698e 105<path>::
165ca621
RS
106 Without an optional path parameter, all files and subdirectories
107 of the current working directory are included in the archive.
108 If one or more paths are specified, only these are included.
4df096a5 109
e8daf78a
FBH
110BACKEND EXTRA OPTIONS
111---------------------
112
113zip
114~~~
c4b208c3
BS
115-<digit>::
116 Specify compression level. Larger values allow the command
117 to spend more time to compress to smaller size. Supported
118 values are from `-0` (store-only) to `-9` (best ratio).
119 Default is `-6` if not given.
e8daf78a 120
c4b208c3
BS
121tar
122~~~
123-<number>::
124 Specify compression level. The value will be passed to the
125 compression command configured in `tar.<format>.command`. See
126 manual page of the configured command for the list of supported
127 levels and the default level if this option isn't specified.
e8daf78a 128
4df096a5
FBH
129CONFIGURATION
130-------------
4df096a5 131
687157c7
RS
132tar.umask::
133 This variable can be used to restrict the permission bits of
134 tar archive entries. The default is 0002, which turns off the
135 world write bit. The special value "user" indicates that the
136 archiving user's umask will be used instead. See umask(2) for
810cae53
RS
137 details. If `--remote` is used then only the configuration of
138 the remote repository takes effect.
4df096a5 139
767cf457
JK
140tar.<format>.command::
141 This variable specifies a shell command through which the tar
142 output generated by `git archive` should be piped. The command
143 is executed using the shell with the generated tar file on its
144 standard input, and should produce the final output on its
145 standard output. Any compression-level options will be passed
146 to the command (e.g., "-9"). An output file with the same
147 extension as `<format>` will be use this format if no other
148 format is given.
0e804e09
JK
149+
150The "tar.gz" and "tgz" formats are defined automatically and default to
151`gzip -cn`. You may override them with custom commands.
767cf457 152
7b97730b
JK
153tar.<format>.remote::
154 If true, enable `<format>` for use by remote clients via
155 linkgit:git-upload-archive[1]. Defaults to false for
156 user-defined formats, but true for the "tar.gz" and "tgz"
157 formats.
158
59a7714c 159[[ATTRIBUTES]]
8d1b9d23
RL
160ATTRIBUTES
161----------
162
163export-ignore::
164 Files and directories with the attribute export-ignore won't be
165 added to archive files. See linkgit:gitattributes[5] for details.
166
167export-subst::
2de9b711 168 If the attribute export-subst is set for a file then Git will
8d1b9d23
RL
169 expand several placeholders when adding this file to an archive.
170 See linkgit:gitattributes[5] for details.
171
9b4c8b0a
JH
172Note 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
fc7642a0 176`.gitattributes` file as necessary and use `--worktree-attributes`
9b4c8b0a
JH
177option. Alternatively you can keep necessary attributes that should apply
178while archiving any tree in your `$GIT_DIR/info/attributes` file.
179
4df096a5
FBH
180EXAMPLES
181--------
5d2fc913 182`git archive --format=tar --prefix=junk/ HEAD | (cd /var/tmp/ && tar xf -)`::
4df096a5
FBH
183
184 Create a tar archive that contains the contents of the
3f7cdf32 185 latest commit on the current branch, and extract it in the
4df096a5
FBH
186 `/var/tmp/junk` directory.
187
5d2fc913 188`git archive --format=tar --prefix=git-1.4.0/ v1.4.0 | gzip >git-1.4.0.tar.gz`::
4df096a5
FBH
189
190 Create a compressed tarball for v1.4.0 release.
191
5d2fc913 192`git archive --format=tar.gz --prefix=git-1.4.0/ v1.4.0 >git-1.4.0.tar.gz`::
0e804e09
JK
193
194 Same as above, but using the builtin tar.gz handling.
195
5d2fc913 196`git archive --prefix=git-1.4.0/ -o git-1.4.0.tar.gz v1.4.0`::
0e804e09
JK
197
198 Same as above, but the format is inferred from the output file.
199
6cf378f0 200`git archive --format=tar --prefix=git-1.4.0/ v1.4.0^{tree} | gzip >git-1.4.0.tar.gz`::
4df096a5
FBH
201
202 Create a compressed tarball for v1.4.0 release, but without a
203 global extended pax header.
204
5d2fc913 205`git archive --format=zip --prefix=git-docs/ HEAD:Documentation/ > git-1.4.0-docs.zip`::
4df096a5
FBH
206
207 Put everything in the current head's Documentation/ directory
208 into 'git-1.4.0-docs.zip', with the prefix 'git-docs/'.
209
5d2fc913 210`git archive -o latest.zip HEAD`::
0f4b377c
DP
211
212 Create a Zip archive that contains the contents of the latest
213 commit on the current branch. Note that the output format is
214 inferred by the extension of the output file.
215
a7591060
RS
216`git archive -o latest.tar --prefix=build/ --add-file=configure --prefix= HEAD`::
217
218 Creates a tar archive that contains the contents of the latest
219 commit on the current branch with no prefix and the untracked
220 file 'configure' with the prefix 'build/'.
221
5d2fc913 222`git config tar.tar.xz.command "xz -c"`::
767cf457
JK
223
224 Configure a "tar.xz" format for making LZMA-compressed tarfiles.
225 You can use it specifying `--format=tar.xz`, or by creating an
226 output file like `-o foo.tar.xz`.
227
8d1b9d23
RL
228
229SEE ALSO
230--------
231linkgit:gitattributes[5]
232
4df096a5
FBH
233GIT
234---
9e1f0a85 235Part of the linkgit:git[1] suite