获取临时添加的远程的“gitlog–tags”
我有这个 repo,它基本上是其他 repos 的列表。我想要做的是运行一个脚本,循环遍历 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仅获取标签。相反,它还会获取最后一次提交。
当我克隆同一个 repo
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分支的一部分。
- 使用
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
如果你在分叉分支上有标签,--simplify-by-decoration也会将合并提交保留在提交列表中;如果您只在“主”分支上寻找标签,请添加--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)