← 返回命令列表

Linux command

git-archive 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Create tar archive of HEAD

git archive HEAD -o [archive.tar]

Create zip archive

git archive --format=zip HEAD -o [archive.zip]

Archive specific commit

git archive [commit] -o [archive.tar]

Archive specific directory

git archive HEAD [path/to/dir] -o [archive.tar]

Archive with prefix

git archive --prefix=[project/] HEAD -o [archive.tar]

Create and compress

git archive HEAD | gzip > [archive.tar.gz]

说明

git archive creates archive files (tar, zip) containing repository content at a specific commit or branch without including the .git directory and other version control metadata. This is essential for creating clean distribution packages and release artifacts. The command supports multiple archive formats including tar, zip, and tar.gz through pipes. Archives can be created from any tree-ish reference (commit, branch, tag) and can include specific subdirectories or use path filtering to include only desired files. Prefix support allows prepending a directory structure to all archived files, useful for creating archives that extract into a specific folder. Remote repository archives can be created without local checkout using the --remote option, though this requires server support.

参数

--format _format_
Archive format (tar, zip, tar.gz).
-o, --output _file_
Output file.
--prefix _prefix_
Prepend prefix to paths.
--remote _repo_
Archive from remote.
-l, --list
List available formats.

FAQ

What is the git-archive command used for?

git archive creates archive files (tar, zip) containing repository content at a specific commit or branch without including the .git directory and other version control metadata. This is essential for creating clean distribution packages and release artifacts. The command supports multiple archive formats including tar, zip, and tar.gz through pipes. Archives can be created from any tree-ish reference (commit, branch, tag) and can include specific subdirectories or use path filtering to include only desired files. Prefix support allows prepending a directory structure to all archived files, useful for creating archives that extract into a specific folder. Remote repository archives can be created without local checkout using the --remote option, though this requires server support.

How do I run a basic git-archive example?

Run `git archive HEAD -o [archive.tar]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --format _format_ do in git-archive?

Archive format (tar, zip, tar.gz).