如何为Git仓库启用ident字符串? [英] How do I enable ident string for Git repos?

查看:112
本文介绍了如何为Git仓库启用ident字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Git存储库中的文件上启用 ident $ Id $

解决方案

摘要: 在产品中嵌入版本信息的推荐方式是使用构建系统请参阅下面的详细信息和替代方法。




在Git中(我认为通常也在其他带有原子提交的VCS系统中)没有像单个文件 版本这样的事情。



Git支持按需扩展 $ Id:$ 关键字,但是:


  1. 仅限。你必须指定(也许使用globbing模式)一个文件(或一组文件)有一个 ident 属性设置(在树中'.gitattributes'文件中,或在本地存储库设置'.git / info / attributes'中)。

  2. 它扩展为文件内容的SHA-1(或者更确切地说是 $ Id:< sha-1 blob> ; $ )。选择此选项的原因是,Git不会触及分支切换或倒带过程中未更改的文件;如果'$ Id:$'扩展到修订版本信息,则需要更新每个版本控制文件。 当转换分支。

Git支持相当多的 $格式:... $ 扩展为提交信息的占位符(例如 $格式:%H $ 替换为提交哈希),但是:


  1. 只有在运行 rel =noreferrer> git archive

  2. 完成应要求,通过 export-subst 属性。

嵌入版本信息的推荐方法是它通过构建系统(在构建阶段);请参阅例如Git Makefile GIT- (b)使用clean / smudge过滤器驱动程序(通过)(ab)使用clean / smudge过滤器驱动程序(通过使用git web界面为git.git存储库) 过滤器属性)来获得类似CVS的关键字扩展,在结帐时扩展关键字,并在输入内容到存储库时进行清理。


How do I enable ident $Id$ on files in a Git repository?

解决方案

Summary: Recommended way of embedding version info in product is to use build system for that; see below for details and alternate approaches.


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 does support on-demand expansion of $Id:$ keyword, but:

  1. 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).
  2. It expands to 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 supports quite a wide set of $Format:...$ placeholders which expands to commit info (e.g. $Format:%H$ replaced by a commit hash) but:

  1. Expansion is done only when running git archive, in its output file.
  2. It is done on request, controlled via export-subst attribute.

The recommended way of embedding version info 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 git web interface for git.git repository.

You can however (ab)use 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 repository.

这篇关于如何为Git仓库启用ident字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆