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