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: tar or zip. If this option is not
31 given, and the output file is specified, the format is inferred
32 from the filename if possible (e.g. writing to "foo.zip" makes the
33 output to be in the zip format). Otherwise the output format is
34 tar.
35
36 -l, --list
37 Show all available formats.
38
39 -v, --verbose
40 Report progress to stderr.
41
42 --prefix=<prefix>/
43 Prepend <prefix>/ to each filename in the archive.
44
45 -o <file>, --output=<file>
46 Write the archive to <file> instead of stdout.
47
48 --add-file=<file>
49 Add a non-tracked file to the archive. Can be repeated to add
50 multiple files. The path of the file in the archive is built by
51 concatenating the value for --prefix (if any) and the basename of
52 <file>.
53
54 --worktree-attributes
55 Look for attributes in .gitattributes files in the working tree as
56 well (see the section called “ATTRIBUTES”).
57
58 <extra>
59 This can be any options that the archiver backend understands. See
60 next section.
61
62 --remote=<repo>
63 Instead of making a tar archive from the local repository, retrieve
64 a tar archive from a remote repository. Note that the remote
65 repository may place restrictions on which sha1 expressions may be
66 allowed in <tree-ish>. See git-upload-archive(1) for details.
67
68 --exec=<git-upload-archive>
69 Used with --remote to specify the path to the git-upload-archive on
70 the remote side.
71
72 <tree-ish>
73 The tree or commit to produce an archive for.
74
75 <path>
76 Without an optional path parameter, all files and subdirectories of
77 the current working directory are included in the archive. If one
78 or more paths are specified, only these are included.
79
81 zip
82 -0
83 Store the files instead of deflating them.
84
85 -9
86 Highest and slowest compression level. You can specify any number
87 from 1 to 9 to adjust compression speed and ratio.
88
90 tar.umask
91 This variable can be used to restrict the permission bits of tar
92 archive entries. The default is 0002, which turns off the world
93 write bit. The special value "user" indicates that the archiving
94 user’s umask will be used instead. See umask(2) for details. If
95 --remote is used then only the configuration of the remote
96 repository takes effect.
97
98 tar.<format>.command
99 This variable specifies a shell command through which the tar
100 output generated by git archive should be piped. The command is
101 executed using the shell with the generated tar file on its
102 standard input, and should produce the final output on its standard
103 output. Any compression-level options will be passed to the command
104 (e.g., "-9"). An output file with the same extension as <format>
105 will be use this format if no other format is given.
106
107 The "tar.gz" and "tgz" formats are defined automatically and
108 default to gzip -cn. You may override them with custom commands.
109
110 tar.<format>.remote
111 If true, enable <format> for use by remote clients via git-upload-
112 archive(1). Defaults to false for user-defined formats, but true
113 for the "tar.gz" and "tgz" formats.
114
116 export-ignore
117 Files and directories with the attribute export-ignore won’t be
118 added to archive files. See gitattributes(5) for details.
119
120 export-subst
121 If the attribute export-subst is set for a file then Git will
122 expand several placeholders when adding this file to an archive.
123 See gitattributes(5) for details.
124
125 Note that attributes are by default taken from the .gitattributes files
126 in the tree that is being archived. If you want to tweak the way the
127 output is generated after the fact (e.g. you committed without adding
128 an appropriate export-ignore in its .gitattributes), adjust the checked
129 out .gitattributes file as necessary and use --worktree-attributes
130 option. Alternatively you can keep necessary attributes that should
131 apply while archiving any tree in your $GIT_DIR/info/attributes file.
132
134 git archive --format=tar --prefix=junk/ HEAD | (cd /var/tmp/ && tar xf
135 -)
136 Create a tar archive that contains the contents of the latest
137 commit on the current branch, and extract it in the /var/tmp/junk
138 directory.
139
140 git archive --format=tar --prefix=git-1.4.0/ v1.4.0 | gzip
141 >git-1.4.0.tar.gz
142 Create a compressed tarball for v1.4.0 release.
143
144 git archive --format=tar.gz --prefix=git-1.4.0/ v1.4.0
145 >git-1.4.0.tar.gz
146 Same as above, but using the builtin tar.gz handling.
147
148 git archive --prefix=git-1.4.0/ -o git-1.4.0.tar.gz v1.4.0
149 Same as above, but the format is inferred from the output file.
150
151 git archive --format=tar --prefix=git-1.4.0/ v1.4.0^{tree} | gzip
152 >git-1.4.0.tar.gz
153 Create a compressed tarball for v1.4.0 release, but without a
154 global extended pax header.
155
156 git archive --format=zip --prefix=git-docs/ HEAD:Documentation/ >
157 git-1.4.0-docs.zip
158 Put everything in the current head’s Documentation/ directory into
159 git-1.4.0-docs.zip, with the prefix git-docs/.
160
161 git archive -o latest.zip HEAD
162 Create a Zip archive that contains the contents of the latest
163 commit on the current branch. Note that the output format is
164 inferred by the extension of the output file.
165
166 git config tar.tar.xz.command "xz -c"
167 Configure a "tar.xz" format for making LZMA-compressed tarfiles.
168 You can use it specifying --format=tar.xz, or by creating an output
169 file like -o foo.tar.xz.
170
172 gitattributes(5)
173
175 Part of the git(1) suite
176
177
178
179Git 2.30.2 2021-03-08 GIT-ARCHIVE(1)