首页 > 解决方案 > git 在结帐时创建二进制文件

问题描述

我正在尝试在 上创建文件git checkout,例如从 tex 文件创建 pdf 或从渐近线源文件创建图像。我知道我可以只签出源文件,然后手动处理它们,但我更喜欢自动完成。到目前为止,我尝试使用 smudge 过滤器,但似乎 smudge 只能修改源文件而不能创建新的二进制文件。关于如何在结帐期间从源文件创建二进制文件的任何想法?

我处理渐近线文件的不成功的涂抹过滤器。如果直接在 shell 中调用,但不能通过 git 调用,效果很好:

#!/bin/bash
cat $1
asy $1 >/dev/null

标签: git

解决方案


好的,根据@torek 的评论,我设法通过创建自己的结帐后挂钩找到了一个可行的解决方案。这个钩子 (in .git/hooks/post-checkout) 将在结帐后对所有 *.asy 文件运行渐近线。因此,它不仅在被检出的文件上运行,因此在具有许多渐近线文件的大型项目中可能会变得相当慢。但它以某种方式起作用,我希望它对其他人也有用。

#!/bin/bash

printf '\npost-checkout hook\nregenerates all asymptote files\n'

# Now find all files ending with .asy and run asymptote on them:
find . -type f -name '*.asy' -execdir asy \{\} \;
# Note that this will recompile ALL asymptote files, not only the possibly changed ones.
# This is because I have no clue on how to check what changed during checkout.

推荐阅读