场合
我们有一个git工作流,其中所有发布版本都堆叠在master
分支上,当提交准备好部署时,我们为其添加一个标记,然后使用git archive
构建一个要部署的捆绑包。
我们使用version.txt
标记的.gitattributes
文件,其中包含选项export-subst
,以跟踪用于构建给定存档的提交。
问题
如果我在$Format:%d$
中编写version.txt
并导出标记的提交,我会在结果文件中写入(HEAD, tag, master)
之类的内容。
如何单独使用tag
?
[edit]有一个git命令已经产生了:
git describe --tags HEAD
这将输出:
latest_tag #if HEAD is tagged
latest_tag-5-g03cc91b #if HEAD is not tagged,
#and the latest tag is 5 commits ago on commit g03cc91b
有没有办法在version.txt
中用这个输出替换一个slug?
答案 0 :(得分:3)
您可以使用content filter driver git checkout会自动执行您想要的确切更改。
(来自Pro Git book 7.2 Customizing Git - Git Attributes)
您在.gitattributes
file smudge
脚本中声明,该脚本将替换特殊标记(您希望替换为git describe --tags HEAD
),而不会触及其他标记由export-subst
上的git archive
修改。
然后你打电话给git archive
,应该(未经测试)替换其余部分。