用 git archive 导出快照

为某提交或标签生成只含跟踪文件的发布压缩包。

macOS归档Git命令行低风险
运行 git archive --format=zip HEAD -o project.zip,导出当前树。

01命令

命令
$ git archive --format=zip HEAD -o project.zip

02作用说明

archive 只写入已跟踪内容,并可用 --prefix 加顶层目录,便于生成可复现的源码发布包或部署包,可在 CI 中脚本化,图形导出对话框做不到。

03风险

风险低风险
使用条件Git 2.20+ (install with Homebrew or Xcode Command Line Tools)
系统兼容性macOS with Git installed (Homebrew or Xcode Command Line Tools)
!注意: 按设计不包含未跟踪和已忽略文件;需要构建产物时请用其他工具。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • git-archive documentation
    Git · vendor-doc · 2026-09-20
    依据: Documents git archive, which exports a tree to a tar or zip archive.

最后验证: 2026-10-13 · 分类: 开发者