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