如何在Git中获取当前分支的最新标签名称?

发布于 2024-08-04 04:42:46 字数 193 浏览 8 评论 0原文

在 Git 中获取最新标签的最简单方法是什么?

git tag a HEAD
git tag b HEAD^^
git tag c HEAD^
git tag

输出:

a
b
c

我应该编写一个脚本来获取每个标签的日期时间并比较它们吗?

What's the simplest way to get the most recent tag in Git?

git tag a HEAD
git tag b HEAD^^
git tag c HEAD^
git tag

output:

a
b
c

Should I write a script to get each tag's datetime and compare them?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(27

玩心态 2024-08-11 04:42:46

获取最新的标签(随后的示例输出):

git describe --tags --abbrev=0   # 0.1.0-dev

获取最新的标签,以及标记对象顶部的附加提交数量更多:

git describe --tags              # 0.1.0-dev-93-g1416689

要获取最新的带注释标签:

git describe --abbrev=0

To get the most recent tag (example output afterwards):

git describe --tags --abbrev=0   # 0.1.0-dev

To get the most recent tag, with the number of additional commits on top of the tagged object & more:

git describe --tags              # 0.1.0-dev-93-g1416689

To get the most recent annotated tag:

git describe --abbrev=0
好多鱼好多余 2024-08-11 04:42:46

将输出所有分支上最新标记提交的标记

git describe --tags $(git rev-list --tags --max-count=1)

Will output the tag of the latest tagged commit across all branches

git describe --tags $(git rev-list --tags --max-count=1)
沉睡月亮 2024-08-11 04:42:46

您可以看一下gitdescribe,它所做的事情与您所要求的很接近。

You could take a look at git describe, which does something close to what you're asking.

红焚 2024-08-11 04:42:46

要获取最新的标签,您可以执行以下操作:

$ git for-each-ref refs/tags --sort=-taggerdate --format='%(refname)' --count=1

当然,您可以根据需要更改计数参数或排序字段。看来
您可能想问一个稍微不同的问题,但这确实回答了我所解释的问题。

To get the most recent tag, you can do:

$ git for-each-ref refs/tags --sort=-taggerdate --format='%(refname)' --count=1

Of course, you can change the count argument or the sort field as desired. It appears
that you may have meant to ask a slightly different question, but this does answer the question as I interpret it.

飞烟轻若梦 2024-08-11 04:42:46

这个怎么样?

TAG=$(git describe $(git rev-list --tags --max-count=1))

从技术上讲,不一定会为您提供最新的标签,但会为您提供标记的最新提交,这可能是也可能不是您正在寻找的东西。

How about this?

TAG=$(git describe $(git rev-list --tags --max-count=1))

Technically, won't necessarily get you the latest tag, but the latest commit which is tagged, which may or may not be the thing you're looking for.

凉薄对峙 2024-08-11 04:42:46

CI/CD 流程中 describe 的问题是您可能会遇到 fatal: no Tags can describe 错误。

之所以会发生这种情况,是因为根据gitdescribe--help

该命令查找可通过提交访问的最新标签。

如果您想要存储库中的最新标签,无论您所在的分支是否可以访问该标签(通常是因为它不是当前分支树的一部分),此命令将为您提供整个存储库中最近创建的标签:

git tag -l --sort=-creatordate | head -n 1

更多详细信息和其他排序键可以在这里找到: https://git -scm.com/docs/git-for-each-ref#_field_names

The problem with describe in CI/CD processes is you can run into the fatal: no tags can describe error.

This will occur because, per git describe --help:

The command finds the most recent tag that is reachable from a commit.

If you want the latest tag in the repo, regardless if the branch you are on can reach the tag, typically because it is not part of the current branch's tree, this command will give you the most recently created tag in the entire repo:

git tag -l --sort=-creatordate | head -n 1

More details and other keys to sort on can be found here: https://git-scm.com/docs/git-for-each-ref#_field_names

温柔戏命师 2024-08-11 04:42:46
git describe --abbrev=0 --tags

如果您没有看到最新标签,请确保在运行之前获取来源:

git remote update
git describe --abbrev=0 --tags

If you don't see latest tag, make sure of fetching origin before running that:

git remote update
决绝 2024-08-11 04:42:46

您可以执行: git describe --tags $(git rev-list --tags --max-count=1) 这里讨论:如何获取最新标签名称?

You can execute: git describe --tags $(git rev-list --tags --max-count=1) talked here: How to get latest tag name?

空气里的味道 2024-08-11 04:42:46

我不确定为什么问题所要求的内容没有答案。即所有标签(包括未注释的)且不带后缀:

git describe --tags --abbrev=0

I'm not sure why there are no answers to what the question is asking for. i.e. All tags (non-annotated included) and without the suffix:

git describe --tags --abbrev=0
物价感观 2024-08-11 04:42:46
git tag --sort=committerdate | tail -1
git tag --sort=committerdate | tail -1
橘香 2024-08-11 04:42:46

“最新”在 git 中可能有两种含义。

您可能的意思是“哪个标签的创建日期最晚”,这里的大多数答案都是针对这个问题的。就您的问题而言,您希望返回标签c

或者你可能指的是“哪个标签在开发历史中最接近某个命名分支”,通常是你所在的分支,HEAD。在您的问题中,这将返回标签 a

当然,这些可能会有所不同:

A->B->C->D->E->F (HEAD)
       \     \
        \     X->Y->Z (v0.2)
         P->Q (v0.1)

想象一下开发人员在周一将 Z 标记为 v0.2,然后将 Q 标记为 <周二代码>v0.1。 v0.1 较新,但 v0.2 在开发历史上更接近 HEAD,因为它所在的路径始于更接近 HEAD 的点。

我想你通常想要第二个答案,更接近开发历史。您可以通过对每个标签使用 git log v0.2..HEAD 等来找到这一点。这为您提供了自以 v0.2 结尾的路径与 HEAD 后面的路径分叉以来 HEAD 上的提交次数。

下面是一个 Python 脚本,它通过迭代运行此检查的所有标签,然后打印出自标签路径分歧以来 HEAD 上提交次数最少的标签来实现此目的:

https://github.com/MacPython/terryfy/blob/master/git-closest-tag

git describe 做的事情略有不同,因为它从(例如)HEAD 回溯以找到在历史记录中从 HEAD 返回的第一个标签。在 git 术语中,gitdescribe 查找可从 HEAD“访问”的标签。因此,它不会找到像 v0.2 这样的标签,这些标签不在从 HEAD 返回的路径上,而是从那里分叉的路径上。

"Most recent" could have two meanings in terms of git.

You could mean, "which tag has the creation date latest in time", and most of the answers here are for that question. In terms of your question, you would want to return tag c.

Or you could mean "which tag is the closest in development history to some named branch", usually the branch you are on, HEAD. In your question, this would return tag a.

These might be different of course:

A->B->C->D->E->F (HEAD)
       \     \
        \     X->Y->Z (v0.2)
         P->Q (v0.1)

Imagine the developer tag'ed Z as v0.2 on Monday, and then tag'ed Q as v0.1 on Tuesday. v0.1 is the more recent, but v0.2 is closer in development history to HEAD, in the sense that the path it is on starts at a point closer to HEAD.

I think you usually want this second answer, closer in development history. You can find that out by using git log v0.2..HEAD etc for each tag. This gives you the number of commits on HEAD since the path ending at v0.2 diverged from the path followed by HEAD.

Here's a Python script that does that by iterating through all the tags running this check, and then printing out the tag with fewest commits on HEAD since the tag path diverged:

https://github.com/MacPython/terryfy/blob/master/git-closest-tag

git describe does something slightly different, in that it tracks back from (e.g.) HEAD to find the first tag that is on a path back in the history from HEAD. In git terms, git describe looks for tags that are "reachable" from HEAD. It will therefore not find tags like v0.2 that are not on the path back from HEAD, but a path that diverged from there.

我们的影子 2024-08-11 04:42:46

git describe --tags

返回当前分支能够看到的最后一个标签

git describe --tags

returns the last tag able to be seen by current branch

以歌曲疗慰 2024-08-11 04:42:46
git tag -l ac* | tail -n1

获取带有前缀“ac”的最后一个标签。例如,以 ac1.0.0ac1.0.5 命名的标记。其他名为 1.0.01.1.0 的标签将被忽略。

git tag -l [0-9].* | tail -n1

获取最后一个标签,其第一个字符是0-9。因此,那些第一个字符为 az 的标签将被忽略。

更多信息

git tag --help # Help for `git tag`

git tag -l <pattern>

列出名称与给定模式匹配的标签(如果没有,则列出所有标签)
给出了模式)。运行不带参数的“git tag”也会列出
所有标签。该模式是一个 shell 通配符(即使用
fnmatch(3))。可以给出多种模式;如果其中任何一个
匹配,显示标签。


tail -n <number> # display the last part of a file
tail -n1 # Display the last item 

使用 git tag --help更新

有关 sort 参数的信息。如果 tag.sort 属性不存在,它将默认使用lexicorgraphic order

排序
默认为为 tag.sort 变量配置的值,如果
存在,否则按字典顺序排列。请参阅 git-config(1)。

经过google,有人说 git 2.8.0 支持以下语法。

git tag --sort=committerdate
git tag -l ac* | tail -n1

Get the last tag with prefix "ac". For example, tag named with ac1.0.0, or ac1.0.5. Other tags named 1.0.0, 1.1.0 will be ignored.

git tag -l [0-9].* | tail -n1

Get the last tag, whose first char is 0-9. So, those tags with first char a-z will be ignored.

More info

git tag --help # Help for `git tag`

git tag -l <pattern>

List tags with names that match the given pattern (or all if no
pattern is given). Running "git tag" without arguments also lists
all tags. The pattern is a shell wildcard (i.e., matched using
fnmatch(3)). Multiple patterns may be given; if any of them
matches, the tag is shown.


tail -n <number> # display the last part of a file
tail -n1 # Display the last item 

Update

With git tag --help, about the sort argument. It will use lexicorgraphic order by default, if tag.sort property doesn't exist.

Sort order
defaults to the value configured for the tag.sort variable if it
exists, or lexicographic order otherwise. See git-config(1).

After google, someone said git 2.8.0 support following syntax.

git tag --sort=committerdate
七月上 2024-08-11 04:42:46
git log --tags --no-walk --pretty="format:%d" | sed 2q | sed 's/[()]//g' | sed s/,[^,]*$// | sed  's ......  '

如果您需要多个最后一个标签

(git描述--tags有时会给出错误的哈希值,我不知道为什么,但对我来说--max-count 2不起作用)

这就是您获取列表的方式最新的 2 个标签名称按时间倒序排列,在 git 1.8.4 上完美运行。
对于早期版本的 git(如 1.7.*),输出中没有“tag:”字符串 - 只需删除最后一个 sed 调用

如果您想要超过 2 个最新标签 - 将此“sed 2q”更改为“sed 5q”或其他你需要

然后你可以轻松地将每个标签名称解析为变量等。

git log --tags --no-walk --pretty="format:%d" | sed 2q | sed 's/[()]//g' | sed s/,[^,]*$// | sed  's ......  '

IF YOU NEED MORE THAN ONE LAST TAG

(git describe --tags sometimes gives wrong hashes, i dont know why, but for me --max-count 2 doesnt work)

this is how you can get list with latest 2 tag names in reverse chronological order, works perfectly on git 1.8.4.
For earlier versions of git(like 1.7.*), there is no "tag: " string in output - just delete last sed call

If you want more than 2 latest tags - change this "sed 2q" to "sed 5q" or whatever you need

Then you can easily parse every tag name to variable or so.

唱一曲作罢 2024-08-11 04:42:46

所有建议有什么错误(除了Matthew Brett解释,此答案帖子的最新内容)?

当您处于不同的历史点时,只需在 jQuery Git 历史记录上运行其他人提供的任何命令,并使用视觉标记历史表示检查结果(我做了这就是您看到这篇文章的原因):

$ git log --graph --all --decorate --oneline --simplify-by-decoration

今天的许多项目在与主线不同的分支中执行发布(以及标记)。

这有强有力的理由。只要看看任何成熟的 JS/CSS 项目即可。对于用户约定,它们在 DVCS 中携带二进制/缩小版本文件。当然,作为项目维护者,您不希望用无用的二进制 blob 来破坏主线 diff 历史记录,并在主线之外执行构建工件的提交。

因为 Git 使用 DAG 而不是线性历史 - 很难定义距离度量,所以我们可以说 - 哦,那个 rev 最接近我的 HEAD

我开始自己的旅程(看看里面,我没有将精美的校样图像复制到这篇长文章中):

过去相对于 Git 中的分支来说最近的标签是什么?

目前我对标签和修订之间的距离有 4 个合理的定义,随着距离的减小有用性:

  • HEAD合并基地最短路径长度,带有
  • 合并基地<的标签日期 /em> 在 HEAD 和标签
  • 转数之间,可以从 HEAD 访问,但无法从标签
  • 日期访问,无论合并基础< /em>

我不知道如何计算最短路径的长度

根据 HEAD 和标签之间的合并基础日期对标签进行排序的脚本:

$ git tag \
     | while read t; do \
         b=`git merge-base HEAD $t`; \
         echo `git log -n 1 $b --format=%ai` $t; \
       done | sort

它可用于大多数项目。

根据可从 HEAD 访问但无法从标签访问的转数对标签进行排序的脚本:

$ git tag \
    | while read t; do echo `git rev-list --count $t..HEAD` $t; done \
    | sort -n

如果您的项目历史记录在提交时有奇怪的日期(由于变基或其他历史记录重写或某些白痴忘记更换 BIOS)电池或您在历史上所做的其他魔法)使用上面的脚本。

对于最后一个选项(标签的日期,无论合并基础)获取按日期排序的标签列表,请使用:

$ git log --tags --simplify-by-decoration --pretty="format:%ci %d" | sort -r

要获取当前修订日期,请使用:

$ git log --max-count=1

请注意 git 描述--tags 有其自身的用途,但不能用于查找项目历史记录中人类预期的最近标签

注意您可以在任何修订中使用上述配方,只需将 HEAD 替换为您想要的即可!

What is wrong with all suggestions (except Matthew Brett explanation, up to date of this answer post)?

Just run any command supplied by other on jQuery Git history when you at different point of history and check result with visual tagging history representation (I did that is why you see this post):

$ git log --graph --all --decorate --oneline --simplify-by-decoration

Todays many project perform releases (and so tagging) in separate branch from mainline.

There are strong reason for this. Just look to any well established JS/CSS projects. For user conventions they carry binary/minified release files in DVCS. Naturally as project maintainer you don't want to garbage your mainline diff history with useless binary blobs and perform commit of build artifacts out of mainline.

Because Git uses DAG and not linear history - it is hard to define distance metric so we can say - oh that rev is most nearest to my HEAD!

I start my own journey in (look inside, I didn't copy fancy proof images to this long post):

What is nearest tag in the past with respect to branching in Git?

Currently I have 4 reasonable definition of distance between tag and revision with decreasing of usefulness:

  • length of shortest path from HEAD to merge base with tag
  • date of merge base between HEAD and tag
  • number of revs that reachable from HEAD but not reachable from tag
  • date of tag regardless merge base

I don't know how to calculate length of shortest path.

Script that sort tags according to date of merge base between HEAD and tag:

$ git tag \
     | while read t; do \
         b=`git merge-base HEAD $t`; \
         echo `git log -n 1 $b --format=%ai` $t; \
       done | sort

It usable on most of projects.

Script that sort tags according to number of revs that reachable from HEAD but not reachable from tag:

$ git tag \
    | while read t; do echo `git rev-list --count $t..HEAD` $t; done \
    | sort -n

If your project history have strange dates on commits (because of rebases or another history rewriting or some moron forget to replace BIOS battery or other magics that you do on history) use above script.

For last option (date of tag regardless merge base) to get list of tags sorted by date use:

$ git log --tags --simplify-by-decoration --pretty="format:%ci %d" | sort -r

To get known current revision date use:

$ git log --max-count=1

Note that git describe --tags have usage on its own cases but not for finding human expected nearest tag in project history.

NOTE You can use above recipes on any revision, just replace HEAD with what you want!

垂暮老矣 2024-08-11 04:42:46

如果您需要最后两个标签(例如,为了生成当前标签和前一个标签之间的更改日志),以下内容对我有用。我仅在最新标签为 HEAD 的情况下对其进行了测试。

PreviousAndCurrentGitTag=`git describe --tags \`git rev-list --tags --abbrev=0 --max-count=2\` --abbrev=0`
PreviousGitTag=`echo $PreviousAndCurrentGitTag | cut -f 2 -d ' '`
CurrentGitTag=`echo $PreviousAndCurrentGitTag | cut -f 1 -d ' '`

GitLog=`git log ${PreviousGitTag}..${CurrentGitTag} --pretty=oneline | sed "s_.\{41\}\(.*\)_; \1_"`

它适合我的需求,但由于我不是 git 向导,我确信它可以进一步改进。我还怀疑如果提交历史向前推进,它会中断。我只是分享以防它对某人有帮助。

The following works for me in case you need last two tags (for example, in order to generate change log between current tag and the previous tag). I've tested it only in situation where the latest tag was the HEAD.

PreviousAndCurrentGitTag=`git describe --tags \`git rev-list --tags --abbrev=0 --max-count=2\` --abbrev=0`
PreviousGitTag=`echo $PreviousAndCurrentGitTag | cut -f 2 -d ' '`
CurrentGitTag=`echo $PreviousAndCurrentGitTag | cut -f 1 -d ' '`

GitLog=`git log ${PreviousGitTag}..${CurrentGitTag} --pretty=oneline | sed "s_.\{41\}\(.*\)_; \1_"`

It suits my needs, but as I'm no git wizard, I'm sure it could be further improved. I also suspect it will break in case the commit history moves forward. I'm just sharing in case it helps someone.

淡莣 2024-08-11 04:42:46

如果您想查找应用于特定分支的最后一个标签,您可以尝试以下操作:

git describe --tag $(git rev-parse --verify refs/remotes/origin/"branch_name")

If you want to find the last tag that was applied on a specific branch you can try the following:

git describe --tag $(git rev-parse --verify refs/remotes/origin/"branch_name")
翻了热茶 2024-08-11 04:42:46

如果您需要一个单行程序来获取当前分支上的最新标签名称(按标签日期):

git for-each-ref refs/tags --sort=-taggerdate --format="%(refname:short)" --count=1 --points-at=HEAD

我们使用它来设置设置中的版本号。

输出示例:

v1.0.0

也适用于 Windows。

If you need a one liner which gets the latest tag name (by tag date) on the current branch:

git for-each-ref refs/tags --sort=-taggerdate --format="%(refname:short)" --count=1 --points-at=HEAD

We use this to set the version number in the setup.

Output example:

v1.0.0

Works on Windows, too.

刘备忘录 2024-08-11 04:42:46

我的第一个想法是你可以使用 git rev-list HEAD ,它按时间倒序列出所有转速,并与 git tag --contains 结合使用。当您找到 git tag --contains 生成非空列表的引用时,您就找到了最新的标签。

My first thought is you could use git rev-list HEAD, which lists all the revs in reverse chronological order, in combination with git tag --contains. When you find a ref where git tag --contains produces a nonempty list, you have found the most recent tag(s).

梦忆晨望 2024-08-11 04:42:46
git tag --sort=-refname | awk 'match($0, /^[0-9]+\.[0-9]+\.[0-9]+$/)' | head -n 1 

该标签获取所有与语义版本控制匹配的分支的最新标签。

git tag --sort=-refname | awk 'match($0, /^[0-9]+\.[0-9]+\.[0-9]+$/)' | head -n 1 

This one gets the latest tag across all branches that matches Semantic Versioning.

素食主义者 2024-08-11 04:42:46

这是一个旧线程,但似乎很多人都错过了OP问题的最简单、最简单、最正确的答案:要获取当前分支的最新标签,您可以使用 git 描述 HEAD。完毕。

编辑:您还可以提供任何有效的引用名称,甚至是遥控器;即,gitdescribeorigin/master会告诉您可以从origin/master到达的最新标签。

This is an old thread, but it seems a lot of people are missing the simplest, easiest, and most correct answer to OP's question: to get the latest tag for the current branch, you use git describe HEAD. Done.

Edit: you can also supply any valid refname, even remotes; i.e., git describe origin/master will tell you the latest tag that can be reached from origin/master.

烟雨扶苏 2024-08-11 04:42:46

对于所问的问题,

如何获取当前分支最新的标签名

您想要的

git log --first-parent --pretty=%d | grep -m1 tag:

最新标签名称--first-parent 告诉 git log 不要详细说明任何合并的历史记录,--pretty=% d 表示仅显示装饰,即任何提交的本地名称。 grep -m1 表示“仅匹配一个”,因此您只获得最新的标签。

For the question as asked,

How to get the latest tag name in the current branch

you want

git log --first-parent --pretty=%d | grep -m1 tag:

--first-parent tells git log not to detail any merged histories, --pretty=%d says to show only the decorations i.e. local names for any commits. grep -m1 says "match just one", so you get just the most-recent tag.

吲‖鸣 2024-08-11 04:42:46

要仅获取以当前分支为前缀的当前分支/标签名称的最新标签,我必须执行以下命令

BRANCH=`git rev-parse --abbrev-ref HEAD` && git describe --tags --abbrev=0 $BRANCH^ | grep $BRANCH

分行负责人:

git checkout master

BRANCH=`git rev-parse --abbrev-ref HEAD` && git describe --tags 
--abbrev=0 $BRANCH^ | grep $BRANCH

master-1448

分支自定义:

git checkout 9.4

BRANCH=`git rev-parse --abbrev-ref HEAD` && git describe --tags 
--abbrev=0 $BRANCH^ | grep $BRANCH

9.4-6

我最后需要增加并为下一个标记获取标签+1。

BRANCH=`git rev-parse --abbrev-ref HEAD` && git describe --tags  --abbrev=0 $BRANCH^ | grep $BRANCH | awk -F- '{print $NF}'

To get the latest tag only on the current branch/tag name that prefixes with current branch, I had to execute the following

BRANCH=`git rev-parse --abbrev-ref HEAD` && git describe --tags --abbrev=0 $BRANCH^ | grep $BRANCH

Branch master:

git checkout master

BRANCH=`git rev-parse --abbrev-ref HEAD` && git describe --tags 
--abbrev=0 $BRANCH^ | grep $BRANCH

master-1448

Branch custom:

git checkout 9.4

BRANCH=`git rev-parse --abbrev-ref HEAD` && git describe --tags 
--abbrev=0 $BRANCH^ | grep $BRANCH

9.4-6

And my final need to increment and get the tag +1 for next tagging.

BRANCH=`git rev-parse --abbrev-ref HEAD` && git describe --tags  --abbrev=0 $BRANCH^ | grep $BRANCH | awk -F- '{print $NF}'
喵星人汪星人 2024-08-11 04:42:46

如果您的标签是可排序的:

git tag --merged $YOUR_BRANCH_NAME | grep "prefix/" | sort | tail -n 1

if your tags are sortable:

git tag --merged $YOUR_BRANCH_NAME | grep "prefix/" | sort | tail -n 1
梦亿 2024-08-11 04:42:46

这里没有太多提及未注释的标签与带注释的标签。 'describe' 适用于带注释的标签并忽略未注释的标签。

这很丑陋,但确实完成了请求的作业,并且不会在其他分支上找到任何标签(而不是在命令中指定的标签上:下例中的 master )

过滤应该优化(合并),但同样,这似乎到工作。

git log  --decorate --tags master |grep '^commit'|grep 'tag:.*)

欢迎批评,因为我现在要使用它:)

|awk '{print $NF}'|sed 's/)$//'|head -n 1

欢迎批评,因为我现在要使用它:)

Not much mention of unannotated tags vs annotated ones here. 'describe' works on annotated tags and ignores unannotated ones.

This is ugly but does the job requested and it will not find any tags on other branches (and not on the one specified in the command: master in the example below)

The filtering should prob be optimized (consolidated), but again, this seems to the the job.

git log  --decorate --tags master |grep '^commit'|grep 'tag:.*)

Critiques welcome as I am going now to put this to use :)

|awk '{print $NF}'|sed 's/)$//'|head -n 1

Critiques welcome as I am going now to put this to use :)

眼趣 2024-08-11 04:42:46

我正在使用这个 bash oneline 命令来获取最新标签或分支名称:

git name-rev --tags --name-only HEAD | cut -d '^' -f 1 | grep -v 'undefined' || git rev-parse --abbrev-ref HEAD

这可以帮助我设置应用程序的版本。

I'm using this bash oneline command to get either the latest tag, either the branch name :

git name-rev --tags --name-only HEAD | cut -d '^' -f 1 | grep -v 'undefined' || git rev-parse --abbrev-ref HEAD

This helps me to set the version of my app.

染墨丶若流云 2024-08-11 04:42:46

下面的命令似乎可以实现从当前提交创建的最近标记(对 glob 模式还不太满意):

git describe --tags --match '*.*.*' --match '*.*.*-*' --match '*.*.*-rc.*' --first-parent --abbrev=0

Below is the command that seems to work to achieve the recently tag created from the current commit (not comfortable yet with the glob pattern):

git describe --tags --match '*.*.*' --match '*.*.*-*' --match '*.*.*-rc.*' --first-parent --abbrev=0
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文