我正在使用git archive创建最新版本或HEAD的zip文件,但希望在zip文件名中添加分支名称和提交信息。我该如何实现这一点?
#!/bin/sh
sha1=`git rev-parse --short --verify HEAD`
branch=`git symbolic-ref -q --short HEAD`
git archive -o latest_${branch}_${sha1}.zip HEAD
比如称其为git-auto-archive
,使其可执行,将其放入您的路径中,并使用以下命令运行:
git auto-archive
git archive -o latest_${branch}_${sha1}.zip
可能会生成一个tar文件而不是zip文件(已修复的错误),如果用于一个--remote
存储库。
查看 提交 00436bf (2018年10月25日),作者为 Josh Steadmon(“”)。
协助者:Jeff King(peff
)。
(由 Junio C Hamano -- gitster
-- 在 提交 a5ab66e 中合并,日期为2018年11月6日)
在运行 git archive
时,尽可能早地初始化归档程序。
各种不明显的行为依赖于已经初始化了归档程序,例如从提供的文件名确定所需的归档格式。
自 08716b3 ("archive
: refactor file extension format-guessing",
2011-06-21, Git v1.7.7-rc0)以来,archive_format_from_filename() 使用注册
的档案器来匹配文件名(通过--output
提供)到归档格式。
然而,当使用 --remote
执行 git archive
时,在注册存档程序之前进行格式检测。
这导致来自远程的存档始终生成为 TAR 文件,而不管实际文件名是什么(除非提供显式的--format
)。
此补丁修复了该行为;即使使用了 --remote
,也能正确地从输出文件名确定归档格式。