简体   繁体   English

如何将“git describe --match”与浅层克隆结合使用?

[英]How can I use “git describe --match” sensibly in combination with a shallow clone?

I am using git describe as the driver for versioning in my application at build time.我在构建时使用git describe作为应用程序版本控制的驱动程序。 It looks roughly like: git describe --always --dirty --match version*它看起来大致像: git describe --always --dirty --match version*

I tag my versions with a pattern like version.1.2.3 and the build figures out the version of the application based off what the last commit that was tagged with something like version.* was.我用类似version.1.2.3的模式标记我的版本,构建根据最后一次提交的内容确定应用程序的版本,该提交标记为类似version.* If I haven't tagged a given commit, then the version number ends up something like version.1.14.3-24-ged66bf5 , which is based of the most recent tag, how many commits since that tag and the git commit id.如果我没有标记给定的提交,那么版本号最终会类似于version.1.14.3-24-ged66bf5 ,它基于最新的标签、自该标签以来的提交次数和 git commit id。

This works really well for me personally, but I'm having a problem with doing builds off of a shallow clone on my CI server.这对我个人来说非常有效,但是我在 CI 服务器上基于浅层克隆进行构建时遇到了问题。

When using the "shallow clone" option on my git build in jenkins (I'm guessing it's just doing "--depth=1"), my git describe command is no longer doing what I want it to do.在 jenkins 的 git 构建中使用“浅克隆”选项时(我猜它只是在执行“--depth = 1”),我的git describe命令不再执行我想要它做的事情。 My version number just ends up being the commit id - I guess this is because there are no tagged versions in the shallow clone, so the --always parameter for the describe command just ends up spitting out the commit id.我的版本号最终只是提交 id - 我猜这是因为浅克隆中没有标记版本,所以 describe 命令的--always参数最终会吐出提交 id。

I can deal with this for the moment by not doing a shallow clone.我暂时可以通过不进行浅层克隆来解决这个问题。

But I really like driving my versioning off of the git describe - how can I keep using it even with shallow clones?但我真的很喜欢从 git describe 驱动我的版本控制 - 即使使用浅克隆,我如何继续使用它? I think what I need to be able to do is specify at the time of the shallow clone, that I want the depth to be "from the tip of the branch back to the latest version that has a tag matching version.* ".我认为我需要能够做的是在浅克隆时指定,我希望深度是“从分支的尖端回到具有标签匹配version.*的最新version.* ”。

Is that a thing I can do with Git?这是我可以用 Git 做的事情吗?

You can't: a shallow clone is missing the tag objects and commits they tag.您不能:浅克隆缺少标记对象并提交它们标记。

More precisely, this depends on the depth of that clone and how far back one must go in history to find appropriate tags.更准确地说,这取决于该克隆的深度以及一个人必须在历史上追溯多远才能找到合适的标签。 Making your shallow clone with --depth 1000 might suffice, for instance.例如,使用--depth 1000制作浅层克隆可能就足够了。 The precise number depends on how many commits you have between 1 the tags you care about.确切的数字取决于您在1 个您关心的标签之间有多少提交。

You are correct that if git provided a "deepen until tagged", that would do the trick, but git doesn't, and worse, deepening a shallow clone does not automatically bring over tags.你是对的,如果 git 提供了一个“深入直到标记”,那就可以解决问题,但 git 没有,更糟糕的是,加深浅克隆不会自动带来标签。

(It would be possible to write a script that uses git ls-remote and git fetch --depth to keep deepening a clone until some tagged commit(s) appear, then have the script apply the tags manually, as it were. This probably would only take a few dozen lines of Python or shell code, for instance, depending on how robust you wanted it. But it's not included with git itself.) (可以编写一个脚本,使用git ls-remotegit fetch --depth继续深化克隆,直到出现一些标记的提交,然后让脚本手动应用标记,就像这样。这可能例如,只需要几十行 Python 或 shell 代码,具体取决于您想要它的健壮程度。但它不包含在 git 本身中。)


1 The notion of "between" is a bit iffy in a non-linear graph, but the general idea should be clear enough here, I think. 1 “介于”的概念在非线性图中有点不确定,但我认为这里的总体思路应该足够清楚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM