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