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