我如何使用“git describe --match”明智地结合浅层克隆? [英] How can I use "git describe --match" sensibly in combination with a shallow clone?

查看:535
本文介绍了我如何使用“git describe --match”明智地结合浅层克隆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 git describe 作为构建时在我的应用程序中进行版本控制的驱动程序。
它看起来大致如下: git describe --always --dirty --match version *



我用 version.1.2.3 这样的模式标记我的版本,并且构建根据最后一次提交的内容标记了 version。* 是。
如果我没有标记给定的提交,那么版本号就会像 version.1.14.3-24-ged66bf5 一样,它是基于最近的标签,自该标签以来提交了多少次提交以及git commit id。



这对我个人而言确实很好,但是我在构建关闭时遇到问题在我的CI服务器上使用浅度克隆。



在jenkins的git build中使用shallow clone选项时(我猜这只是在做--depth = 1),我的git describe命令不再按照我希望的方式执行。
我的版本号最后只是提交ID - 我想这是因为在浅克隆中没有标签版本,所以 - 总是参数这个describe命令只是结束了提交id。



我可以通过不做浅层克隆来解决这个问题。 但是我真的很喜欢把我的版本从git描述中解放出来 - 即使是浅层克隆我怎么能继续使用它?
我认为我需要做的是在浅层克隆时指定深度为从分支的顶端返回到标签匹配<$的最新版本c $ c> version。* 。



这是我可以用Git做的事吗?

解决方案

不能:浅层克隆缺少标记对象并提交它们标记。



更准确地说,这取决于该克隆的深度,以及历史中为找到适当标签而必须走多远。例如,使用 - 深度1000 来制作浅色克隆就足够了。确切的数字取决于您在 1 您关心的标签之间提交的提交数量。



如果git提供了深化直到被标记为,这将做的伎俩,但git没有,更糟糕的是,加深浅层克隆不会自动带来标签。



编写一个脚本,该脚本使用 git ls-remote git fetch --depth 来继续深化克隆,直到某些标记提交(s)出现,然后让脚本手动应用标签,例如,这可能只需要几十行Python或shell代码,具体取决于你想要的强大程度,但它不包含在)






1 between的概念在a非线性图,但我认为这里的一般想法应该足够清楚。


I am using git describe as the driver for versioning in my application at build time. It looks roughly like: 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. 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.

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.

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. 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.

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? 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.*".

Is that a thing I can do with 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. The precise number depends on how many commits you have between1 the tags you care about.

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.

(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.)


1The notion of "between" is a bit iffy in a non-linear graph, but the general idea should be clear enough here, I think.

这篇关于我如何使用“git describe --match”明智地结合浅层克隆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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