如何使用自标记以来的提交次数显示git commit [英] How to show git commit using number of commits since a tag

查看:135
本文介绍了如何使用自标记以来的提交次数显示git commit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用git describe,您可以获取自上一个标记以来的提交次数.如果只有标签和提交次数,那么显示所描述的提交的最佳方法是什么?

With git describe you can get the number of commits since the last tag. If you only had the tag and the number of commits what is the best way to show the commit that was described?

我知道您可以使用git log tag..并将其通过管道传递到执行计数的脚本,但是我希望找到一种类似于git show tag~n的更优雅的解决方案.

I know you could use git log tag.. and pipe it to a a script that does the counting but I was hoping for a more elegant solution similar to git show tag~n.

要添加更多上下文,我们计划使用git describe创建版本号,例如

To add more context, we are planning using git describe to create release numbers, for example with

$ git describe
v1.5-39-g5ede964

我们将使用foo_1.5.39.我们想做的是知道1.5.39表示v1.5标签之后的第39个提交,找到该提交,即找到g5ede964.正如评论中指出的那样,v1.5之后的第39次提交可能不是唯一的.因此,也许最好的方法是找到所有提交X的最佳方法是什么,以便如果HEAD指向X git describe会返回 v1.5-39-*****.

we would use foo_1.5.39. What we would like to do is knowing 1.5.39 means the 39th commit after the v1.5 tag, find that commit, i.e. find g5ede964. As pointed out in a comment, the 39th commit after v1.5 may not be unique. So perhaps a better way to ask this is what is the best way to find all commits X such that if HEAD was pointing to X git describe would return v1.5-39-*****.

推荐答案

通常情况下,您所要求的是不可能的.如果您的历史记录中有任何合并,仅提交次数就无法告诉您任何信息.

What you're asking for is impossible in the general case. The number of commits alone can't tell you anything if there are any merges in your history.

例如,给定以下回购结构:

For example, given the following repo structure:

a - b - c - d - h
  \           /
    e - f - g

a上放置标签后,git describe dgit describe g的输出相同,但SHA1除外:

With a tag put on a, the outputs of git describe d and git describe g are identical save for the SHA1:

> git describe d
tag-3-ge8dca33
> git describe g
tag-3-g4fecc2e

也就是说,如果您一次没有一堆并行分支,那么您也许可以将给定的提交号解析回单个提交,但是如果您在同一位置只有一个活动的分支,标签的时间,那么这可能无法正常工作.

That said, if you don't have a bunch of parallel branches going on at once, then you may be able to resolve a given commit number back to a single commit, but if you have even a single active side branch at the time of your tag then this may not work.

如果您需要可靠的版本号,则应使用明确的标签.

If you need reliable release numbers, you should stick to explicit tags.

这篇关于如何使用自标记以来的提交次数显示git commit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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