Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 1 | git-archive(1) |
| 2 | ============== |
| 3 | |
| 4 | NAME |
| 5 | ---- |
Junio C Hamano | 4ec0671 | 2007-06-09 20:39:33 | [diff] [blame] | 6 | git-archive - Create an archive of files from a named tree |
Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 7 | |
| 8 | |
| 9 | SYNOPSIS |
| 10 | -------- |
Junio C Hamano | a9b8d24 | 2007-05-19 04:51:55 | [diff] [blame] | 11 | [verse] |
Junio C Hamano | e367f7b | 2009-08-28 09:18:28 | [diff] [blame] | 12 | 'git archive' [--format=<fmt>] [--list] [--prefix=<prefix>/] [<extra>] |
Junio C Hamano | 3d1b5a1 | 2013-05-17 23:34:02 | [diff] [blame] | 13 | [-o <file> | --output=<file>] [--worktree-attributes] |
Junio C Hamano | 764a667 | 2007-10-23 01:23:31 | [diff] [blame] | 14 | [--remote=<repo> [--exec=<git-upload-archive>]] <tree-ish> |
Junio C Hamano | d2179ef | 2010-10-22 04:12:17 | [diff] [blame] | 15 | [<path>...] |
Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 16 | |
| 17 | DESCRIPTION |
| 18 | ----------- |
| 19 | Creates an archive of the specified format containing the tree |
Junio C Hamano | 58155b4 | 2007-09-15 07:46:14 | [diff] [blame] | 20 | structure for the named tree, and writes it out to the standard |
| 21 | output. If <prefix> is specified it is |
Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 22 | prepended to the filenames in the archive. |
| 23 | |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 24 | 'git archive' behaves differently when given a tree ID versus when |
Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 25 | given a commit ID or tag ID. In the first case the current time is |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 26 | used as the modification time of each file in the archive. In the latter |
Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 27 | case the commit time as recorded in the referenced commit object is |
| 28 | used instead. Additionally the commit ID is stored in a global |
| 29 | extended pax header if the tar format is used; it can be extracted |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 30 | using 'git get-tar-commit-id'. In ZIP files it is stored as a file |
Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 31 | comment. |
| 32 | |
| 33 | OPTIONS |
| 34 | ------- |
| 35 | |
| 36 | --format=<fmt>:: |
Junio C Hamano | d6fff40 | 2009-09-14 09:40:50 | [diff] [blame] | 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`. |
Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 42 | |
Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 43 | -l:: |
| 44 | --list:: |
Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 45 | Show all available formats. |
| 46 | |
Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 47 | -v:: |
| 48 | --verbose:: |
Junio C Hamano | 81c711d | 2007-04-20 07:20:14 | [diff] [blame] | 49 | Report progress to stderr. |
| 50 | |
Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 51 | --prefix=<prefix>/:: |
Junio C Hamano | 80b2839 | 2022-06-07 21:53:15 | [diff] [blame^] | 52 | Prepend <prefix>/ to paths in the archive. Can be repeated; its |
| 53 | rightmost value is used for all tracked files. See below which |
| 54 | value gets used by `--add-file` and `--add-virtual-file`. |
Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 55 | |
Junio C Hamano | d6fff40 | 2009-09-14 09:40:50 | [diff] [blame] | 56 | -o <file>:: |
Junio C Hamano | 36ac993 | 2009-03-05 09:57:10 | [diff] [blame] | 57 | --output=<file>:: |
| 58 | Write the archive to <file> instead of stdout. |
| 59 | |
Junio C Hamano | d128151 | 2020-10-05 22:21:55 | [diff] [blame] | 60 | --add-file=<file>:: |
| 61 | Add a non-tracked file to the archive. Can be repeated to add |
Junio C Hamano | 80b2839 | 2022-06-07 21:53:15 | [diff] [blame^] | 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>. |
| 65 | |
| 66 | --add-virtual-file=<path>:<content>:: |
| 67 | Add the specified contents to the archive. Can be repeated to add |
Junio C Hamano | d128151 | 2020-10-05 22:21:55 | [diff] [blame] | 68 | multiple files. The path of the file in the archive is built |
Junio C Hamano | 80b2839 | 2022-06-07 21:53:15 | [diff] [blame^] | 69 | by concatenating the value of the last `--prefix` option (if any) |
| 70 | before this `--add-virtual-file` and `<path>`. |
| 71 | + |
| 72 | The `<path>` argument can start and end with a literal double-quote |
| 73 | character; the contained file name is interpreted as a C-style string, |
| 74 | i.e. the backslash is interpreted as escape character. The path must |
| 75 | be quoted if it contains a colon, to avoid the colon from being |
| 76 | misinterpreted as the separator between the path and the contents, or |
| 77 | if the path begins or ends with a double-quote character. |
| 78 | + |
| 79 | The file mode is limited to a regular file, and the option may be |
| 80 | subject to platform-dependent command-line limits. For non-trivial |
| 81 | cases, write an untracked file and use `--add-file` instead. |
Junio C Hamano | d128151 | 2020-10-05 22:21:55 | [diff] [blame] | 82 | |
Junio C Hamano | 4cfa536 | 2009-04-18 23:01:01 | [diff] [blame] | 83 | --worktree-attributes:: |
Junio C Hamano | 0eb1150 | 2013-04-12 02:14:19 | [diff] [blame] | 84 | Look for attributes in .gitattributes files in the working tree |
| 85 | as well (see <<ATTRIBUTES>>). |
Junio C Hamano | 4cfa536 | 2009-04-18 23:01:01 | [diff] [blame] | 86 | |
Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 87 | <extra>:: |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 88 | This can be any options that the archiver backend understands. |
Junio C Hamano | 817abb4 | 2006-09-26 07:16:58 | [diff] [blame] | 89 | See next section. |
Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 90 | |
| 91 | --remote=<repo>:: |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 92 | Instead of making a tar archive from the local repository, |
Junio C Hamano | 81703b2 | 2014-03-14 22:00:27 | [diff] [blame] | 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. |
Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 97 | |
Junio C Hamano | 764a667 | 2007-10-23 01:23:31 | [diff] [blame] | 98 | --exec=<git-upload-archive>:: |
| 99 | Used with --remote to specify the path to the |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 100 | 'git-upload-archive' on the remote side. |
Junio C Hamano | 764a667 | 2007-10-23 01:23:31 | [diff] [blame] | 101 | |
Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 102 | <tree-ish>:: |
| 103 | The tree or commit to produce an archive for. |
| 104 | |
Junio C Hamano | d2179ef | 2010-10-22 04:12:17 | [diff] [blame] | 105 | <path>:: |
Junio C Hamano | e5574b6 | 2009-12-06 04:04:45 | [diff] [blame] | 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. |
Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 109 | |
Junio C Hamano | 817abb4 | 2006-09-26 07:16:58 | [diff] [blame] | 110 | BACKEND EXTRA OPTIONS |
| 111 | --------------------- |
| 112 | |
| 113 | zip |
| 114 | ~~~ |
Junio C Hamano | 19dcd3f | 2021-10-29 23:20:47 | [diff] [blame] | 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. |
Junio C Hamano | 817abb4 | 2006-09-26 07:16:58 | [diff] [blame] | 120 | |
Junio C Hamano | 19dcd3f | 2021-10-29 23:20:47 | [diff] [blame] | 121 | tar |
| 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. |
Junio C Hamano | 817abb4 | 2006-09-26 07:16:58 | [diff] [blame] | 128 | |
Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 129 | CONFIGURATION |
| 130 | ------------- |
Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 131 | |
Junio C Hamano | bdebabb | 2007-08-23 00:25:09 | [diff] [blame] | 132 | tar.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 |
Junio C Hamano | f75a940 | 2011-04-14 23:39:23 | [diff] [blame] | 137 | details. If `--remote` is used then only the configuration of |
| 138 | the remote repository takes effect. |
Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 139 | |
Junio C Hamano | 708376e | 2011-07-19 20:02:13 | [diff] [blame] | 140 | tar.<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. |
| 149 | + |
| 150 | The "tar.gz" and "tgz" formats are defined automatically and default to |
| 151 | `gzip -cn`. You may override them with custom commands. |
| 152 | |
| 153 | tar.<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 | |
Junio C Hamano | 0eb1150 | 2013-04-12 02:14:19 | [diff] [blame] | 159 | [[ATTRIBUTES]] |
Junio C Hamano | a9eca4e | 2009-03-04 08:29:59 | [diff] [blame] | 160 | ATTRIBUTES |
| 161 | ---------- |
| 162 | |
| 163 | export-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 | |
| 167 | export-subst:: |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 168 | If the attribute export-subst is set for a file then Git will |
Junio C Hamano | a9eca4e | 2009-03-04 08:29:59 | [diff] [blame] | 169 | expand several placeholders when adding this file to an archive. |
| 170 | See linkgit:gitattributes[5] for details. |
| 171 | |
Junio C Hamano | 1123f30 | 2010-02-12 20:51:24 | [diff] [blame] | 172 | Note that attributes are by default taken from the `.gitattributes` files |
| 173 | in the tree that is being archived. If you want to tweak the way the |
| 174 | output is generated after the fact (e.g. you committed without adding an |
| 175 | appropriate export-ignore in its `.gitattributes`), adjust the checked out |
Junio C Hamano | 8143563 | 2011-01-12 09:08:48 | [diff] [blame] | 176 | `.gitattributes` file as necessary and use `--worktree-attributes` |
Junio C Hamano | 1123f30 | 2010-02-12 20:51:24 | [diff] [blame] | 177 | option. Alternatively you can keep necessary attributes that should apply |
| 178 | while archiving any tree in your `$GIT_DIR/info/attributes` file. |
| 179 | |
Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 180 | EXAMPLES |
| 181 | -------- |
Junio C Hamano | 16ebcd0 | 2011-08-05 00:05:45 | [diff] [blame] | 182 | `git archive --format=tar --prefix=junk/ HEAD | (cd /var/tmp/ && tar xf -)`:: |
Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 183 | |
| 184 | Create a tar archive that contains the contents of the |
Junio C Hamano | fd83b8e | 2009-03-22 08:21:41 | [diff] [blame] | 185 | latest commit on the current branch, and extract it in the |
Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 186 | `/var/tmp/junk` directory. |
| 187 | |
Junio C Hamano | 16ebcd0 | 2011-08-05 00:05:45 | [diff] [blame] | 188 | `git archive --format=tar --prefix=git-1.4.0/ v1.4.0 | gzip >git-1.4.0.tar.gz`:: |
Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 189 | |
| 190 | Create a compressed tarball for v1.4.0 release. |
| 191 | |
Junio C Hamano | 16ebcd0 | 2011-08-05 00:05:45 | [diff] [blame] | 192 | `git archive --format=tar.gz --prefix=git-1.4.0/ v1.4.0 >git-1.4.0.tar.gz`:: |
Junio C Hamano | 708376e | 2011-07-19 20:02:13 | [diff] [blame] | 193 | |
| 194 | Same as above, but using the builtin tar.gz handling. |
| 195 | |
Junio C Hamano | 16ebcd0 | 2011-08-05 00:05:45 | [diff] [blame] | 196 | `git archive --prefix=git-1.4.0/ -o git-1.4.0.tar.gz v1.4.0`:: |
Junio C Hamano | 708376e | 2011-07-19 20:02:13 | [diff] [blame] | 197 | |
| 198 | Same as above, but the format is inferred from the output file. |
| 199 | |
Junio C Hamano | b76a686 | 2012-05-02 22:02:46 | [diff] [blame] | 200 | `git archive --format=tar --prefix=git-1.4.0/ v1.4.0^{tree} | gzip >git-1.4.0.tar.gz`:: |
Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 201 | |
| 202 | Create a compressed tarball for v1.4.0 release, but without a |
| 203 | global extended pax header. |
| 204 | |
Junio C Hamano | 16ebcd0 | 2011-08-05 00:05:45 | [diff] [blame] | 205 | `git archive --format=zip --prefix=git-docs/ HEAD:Documentation/ > git-1.4.0-docs.zip`:: |
Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 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 | |
Junio C Hamano | 16ebcd0 | 2011-08-05 00:05:45 | [diff] [blame] | 210 | `git archive -o latest.zip HEAD`:: |
Junio C Hamano | d6fff40 | 2009-09-14 09:40:50 | [diff] [blame] | 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 | |
Junio C Hamano | 80b2839 | 2022-06-07 21:53:15 | [diff] [blame^] | 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 | |
Junio C Hamano | 16ebcd0 | 2011-08-05 00:05:45 | [diff] [blame] | 222 | `git config tar.tar.xz.command "xz -c"`:: |
Junio C Hamano | 708376e | 2011-07-19 20:02:13 | [diff] [blame] | 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 | |
Junio C Hamano | a9eca4e | 2009-03-04 08:29:59 | [diff] [blame] | 228 | |
| 229 | SEE ALSO |
| 230 | -------- |
| 231 | linkgit:gitattributes[5] |
| 232 | |
Junio C Hamano | 781d8a2 | 2006-09-17 10:34:15 | [diff] [blame] | 233 | GIT |
| 234 | --- |
Junio C Hamano | f7c042d | 2008-06-06 22:50:53 | [diff] [blame] | 235 | Part of the linkgit:git[1] suite |