每次 git Push 完成后都会更新版本吗?
我们如何在每次推送时使用 git 更改版本(每个+1)?
例如,我每个标题上都有一个 2 php 文件,
libs/lib1.php
libs/lib2.php
通常会有一些信息,例如
/**
* LIB1.PHP
* this libs does something like this
* and that this is a doc for you
* @version 145
* @todo something todo
* @author DAMS
*/
/**
* LIB2.PHP
* this libs does something like this
* and that this is a doc for you
* @version 445
* @todo something todo
* @author DAMS
*/
我们可以在每次推送时搜索并添加 +1 do 版本吗?
how do we do like changing version ( each +1 ) using git on each push?
example i have a 2 php file
libs/lib1.php
libs/lib2.php
on each header usually there is some information like
/**
* LIB1.PHP
* this libs does something like this
* and that this is a doc for you
* @version 145
* @todo something todo
* @author DAMS
*/
/**
* LIB2.PHP
* this libs does something like this
* and that this is a doc for you
* @version 445
* @todo something todo
* @author DAMS
*/
can we search and add +1 do version every time we push?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您所要求的本质上是关键字扩展。首先,请查看 Git 常见问题解答问题“git 是否有关键字扩展?”。它说:
所以 git 确实有类似关键字扩展的功能,尽管不推荐。 Git 也没有“文件修订版”的概念(这就是您的
@version
编号),因此这无法准确地提供您所要求的内容为了。您也可以创建一个挂钩(可能是预接收挂钩?),这将为您增加版本。这只是一个可执行文件(因此它可以是 shell/Python/Perl/Ruby/任何您喜欢的脚本),当您执行推送时,它会自动执行。请参阅 githooks 手册页。
您的挂钩脚本将:
@version \d+
的版本请注意,这至少与使用 Git FAQ 建议反对的关键字扩展一样糟糕,甚至可能更糟糕。这可能会导致恼人的合并冲突。您也可能很容易在代码中出现误导性的版本号,特别是如果您必须向旧版本提交错误修复,尽管每当您合并来自多个存储库/分支的更改时也可能会发生这种情况(这对于大多数人来说很常见) git 工作流程)如果你不小心的话。
What you're asking for is essentially keyword expansion. To start, take a look at the Git FAQ question "Does git have keyword expansion?". It says:
So git does have something like keyword expansion, though it's not recommended. Git also doesn't have the concept of a "file revision" (which is what your
@version
number appears to be), so this wouldn't be able to give you exactly what you're asking for.You could alternatively create a hook (probably a pre-receive hook?), that would increment the version for you. This is just an executable (so it can be a shell/ Python/ Perl/ Ruby/ whatever-you're-comfortable-with script) that'll get executed automatically when you do a push. See the githooks man page.
Your hook script would:
@version \d+
Note that this is at least as bad as using the keyword expansion that the Git FAQ recommends against, and possibly much worse. This will likely to lead to annoying merge conflicts. You could also easily end up with misleading version numbers in your code, especially if you ever have to commit a bugfix to an older version, though it will probably also happen whenever you merge changes from multiple repos/branches (which is pretty common with most git workflows) if you aren't careful.