git - 获取临时添加的 Remote 的 "git log --tags"

标签 git

我有这个存储库,它基本上是其他存储库的列表。我想要做的是运行一个脚本,该脚本循环访问 URL 列表并获取有关其上次发布日期(标签)的信息。

<for each url in my list>
git remote remove tmp
git remote add tmp https://url-to-another-repo.git
git fetch tmp master
git log tmp/master --tags="*" --max-count=1 --pretty="Last updated %ar"
<next url>

效果还不错,但不是我想要的方式。我无法让 git log 仅获取标签。相反,它还获取最后的提交。

当我克隆相同的存储库时

git clone https://url-to-another-repo.git
git log --tags="*" --max-count=1 --pretty="Last updated %ar"

它显示了正确的结果 - 即:仅最后一个标记提交。

最佳答案

--tags="*"并不像您想象的那样:它就像您在命令行上列出了所有标签一样;所以:

git log --tags="*"
# is roughly equivalent to
git log last-stable my/tag v1.0.1 v1.0.2  # whatever tags you have on your repo

git log --tags="*" tmp/master
# is roughly equivalent to
git log tmp/master last-stable my/tag v1.0.1 v1.0.2
  • 在第一种情况下:第一个提交(通过添加 -1 选项获得的提交)将始终被标记,但您不知道该标记是否是当前分支的一部分,

  • 在第二种情况下,如果 tmp/master是最上面的提交,它不会被标记,并且如果标记恰好在 tmp/master 之前再次,您不知道该标签是否是 tmp/master 的一部分分支。


  1. 使用git log ,您可以尝试组合--simplify-by-decoration--decorate-refs=<pattern> :
git log --decorate-refs="refs/tags" --simplify-by-decoration

# you can also filter tags using patterns :
# will list tags "v1.0.1" and "v2.0.3", but not "testing"
git log --decorate-refs="refs/tags/v*" --simplify-by-decoration

如果 fork 分支上有标签,--simplify-by-decoration还将把 merge 提交保留在提交列表中;如果您仅在“主”分支上查找标签,请添加 --first-parent :

git log --first-parent --decorate-refs="refs/tags" --simplify-by-decoration
  • 另一个选项是 git describe :
  • # this will give you "the last tag on the branch" (for some definition of "last tag")
    git describe --tags --abbrev=0 tmp/master
    
    # you can combine it with 'git log' :
    git log -1 $(git describe --tags --abbrev=0 tmp/master)
    

    关于git - 获取临时添加的 Remote 的 "git log --tags",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66220174/

    相关文章:

    git - 如何处理重复的哈希值

    c++ - 作为 DLL 的 GIT C/C++ 库

    git - Android Studio git commit 看不到我修改过的文件

    git - 我们可以在 Azure DevOps 中锁定文件吗?

    git - 多个 Git 修复提交

    git - 使用 git flow 发布时,我应该如何更新 pom.xml 中的版本?

    php - 有没有办法让 git diff 显示方法名而不是类名?

    android - 在 2 台计算机上的 Android Studio 中开发 - 并且 app.iml 始终更改

    Git ssh 无法解析主机名

    git - 是否可以替换 git merge 算法?