如何为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:<sha-1 of blob>$
).选择该选项的原因是,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- Makefile在git.git存储库的Git Web界面中使用的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屋!