git 是否有类似 `svn propset svn:keywords` 或 pre-/post-commit 的钩子? [英] Does git have anything like `svn propset svn:keywords` or pre-/post-commit hooks?

查看:20
本文介绍了git 是否有类似 `svn propset svn:keywords` 或 pre-/post-commit 的钩子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

浏览 git 文档,我看不到任何类似于 SVN 的提交挂钩或propset"功能的内容,例如,只要将文件提交到存储库,就可以更新文件中的版本号或版权声明.

Browsing through the git documentation, I can't see anything analogous to SVN's commit hooks or the "propset" features that can, say, update a version number or copyright notice within a file whenever it is committed to the repository.

git 用户是希望为这种功能编写外部脚本(这似乎不是不可能的)还是我只是遗漏了一些明显的东西?

Are git users expected to write external scripts for this sort of functionality (which doesn't seem out of the question) or have I just missed something obvious?

Edit :为了清楚起见,我更感兴趣,例如,

Edit : Just to be clear, I'm more interested in, e.g.,

svn propset svn:keywords "Author Date Id Revision" expl3.dtx

像这样的字符串:

$Id: expl3.dtx 780 2008-08-30 12:32:34Z morten $

在发生提交时随时更新相关信息.

is kept up-to-date with the relevant info whenever a commit occurs.

推荐答案

引用自 Git 常见问题:

git有关键字扩展吗?

Does git have keyword expansion?

不推荐.关键字扩展导致各种奇怪的问题和无论如何都不是很有用,尤其是在 SCM 的上下文中.外部git 您可以使用脚本执行关键字扩展.Linux内核导出脚本执行此操作以在 Makefile 中设置 EXTRA_VERSION 变量.

Not recommended. Keyword expansion causes all sorts of strange problems and isn't really useful anyway, especially within the context of an SCM. Outside git you may perform keyword expansion using a script. The Linux kernel export script does this to set the EXTRA_VERSION variable in the Makefile.

如果你真的想这样做,请参阅 gitattributes(5).如果您的翻译不是可逆的(例如 SCCS 关键字扩展)这可能有问题.

See gitattributes(5) if you really want to do this. If your translation is not reversible (eg SCCS keyword expansion) this may be problematic.

这篇关于git 是否有类似 `svn propset svn:keywords` 或 pre-/post-commit 的钩子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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