如何为 Git 存储库启用 ident 字符串? [英] How do I enable the ident string for a Git repository?
问题描述
如何在 Git 存储库中的文件上启用 ident $Id$
?
How do I enable ident $Id$
on files in a Git repository?
推荐答案
总结: 在产品中嵌入版本信息的推荐方式是使用 为此构建系统;有关详细信息和替代方法,请参见下文.
Summary: The recommended way of embedding version information in a product is to use the build system for that; see below for details and alternate approaches.
在 Git 中(我认为在其他具有原子提交的 VCS 系统中通常也有)没有像一个单个文件的版本这样的东西.
In Git (and I think usually also in other VCS systems with atomic commits) there is no such thing like version of a single file.
Git 确实支持 $Id:$
关键字的按需扩展,但是:
Git does support on-demand expansion of $Id:$
keyword, but:
- 仅应要求完成.您必须指定(可能使用通配模式)一个文件(或一组文件)具有
ident
属性 集(在树中的 '.gitattributes' 文件中,或在本地存储库设置的 '.git/info/attributes' 中). - 它扩展到文件内容的 SHA-1(或更准确地说是
$Id:
).这个选择的原因是,在分支切换或回绕过程中,Git 不会接触没有改变的文件;如果$Id:$"扩展为修订信息,则需要更新每个版本控制文件,例如切换分支时.$
- It is done on request only. You have to specify (perhaps using globbing pattern) that a file (or a set of files) has an
ident
attribute set (in '.gitattributes' file in tree, or in '.git/info/attributes' for local repository settings). - It expands to the SHA-1 of file contents (or to be more exact to
$Id:<sha-1 of blob>$
). The reason for this choice is that Git does not touch files that have not changed during branch switching or rewinding; if '$Id:$' expanded to revision info it would require to update every version-controlled file e.g. when switching branches.
Git 支持相当多的 $Format:...$
占位符,这些占位符扩展到提交信息(例如 $Format:%H$
被提交哈希替换) 但是:
Git supports quite a wide set of $Format:...$
placeholders which expands to commit information (e.g. $Format:%H$
replaced by a commit hash) but:
- 扩展仅在运行 git 时完成存档,在其输出文件中.
- 它根据请求完成,通过
export-subst
属性控制.
- Expansion is done only when running git archive, in its output file.
- It is done on request, controlled via
export-subst
attribute.
推荐的嵌入版本信息的方式是通过构建系统(在构建阶段);参见例如 Git Makefile 和 GIT-git.git 存储库的 Git Web 界面中 Makefile 使用的 VERSION-GEN 脚本.
The recommended way of embedding version information is to do it via the build system (in a build stage); see for example Git Makefile and GIT-VERSION-GEN script used by Makefile in the Git web interface for the git.git repository.
然而,您可以 (ab) 使用清洁/涂抹过滤器驱动程序(通过 filter
属性)获得类似 CVS 的关键字扩展,在结帐时扩展关键字,并在将内容输入到存储库.
You can however (ab)use a clean/smudge filter driver (via filter
attribute) to get CVS-like keyword expansion, expanding keywords on checkout, and cleaning them up on entering contents to the repository.
这篇关于如何为 Git 存储库启用 ident 字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!