Git 变更日志:如何获取特定标签的所有更改?

发布于 2024-12-04 06:49:34 字数 359 浏览 3 评论 0原文

有没有一种简单的方法或命令可以让所有 git 提交到特定标签来为项目生成自动变更日志?我总是使用 v0.1.0 之类的版本号来标记我的 git 存储库,例如希望所有提交都达到标记 v0.1.0

我浏览了文档,但似乎没有找到有用的选项或命令: http://git- scm.com/docs/git-log (顺便说一句,目前已关闭)

例如:

$ git log --oneline --decorate

显示提交旁边的标签。我想要同样的,但仅限于特定标签。

Is there an easy way or command to get all git commits up to a specific tag to generate an automatic changelog for a project? I always tag my git repos with a version number like v0.1.0 and for instance would like all commits up to tag v0.1.0.

I've looked through the docs but don't seem to find a useful option or command for it: http://git-scm.com/docs/git-log (is down at the moment by the way)

For instance:

$ git log --oneline --decorate

Shows the tags next to commits. I'd like the same, but only up to specific tag.

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

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

发布评论

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

评论(10

末蓝 2024-12-11 06:49:34

您可以这样做:

git log --oneline --decorate v0.1.0

... 显示 v0.1.0 之前(包括 v0.1.0)的每个提交。当然, git log 还允许您限制以 git rev-list 理解的任何方式显示的提交,因此如果您只想查看之间的更改v0.0.9v0.1.0 您也可以这样做:

git log --oneline --decorate v0.0.9..v0.1.0

可能对此目的有用的替代输出是 git Shortlog 的输出,它将并总结了每位作者的贡献。尝试一下,例如:

git shortlog v0.1.0

You can just do:

git log --oneline --decorate v0.1.0

... to show every commit up to and including v0.1.0. Of course, git log allows also allows you to restrict the commits shown in any of the ways that git rev-list understands, so if you only wanted to see the changes between v0.0.9 and v0.1.0 you could also do:

git log --oneline --decorate v0.0.9..v0.1.0

Alternative output that might be useful for this purpose is that of git shortlog, which groups and summarizes the contributions of each author. Try, for example:

git shortlog v0.1.0
暖心男生 2024-12-11 06:49:34

为了通过标签创建变更日志,我使用了这个脚本:

#!/bin/bash
# Author:Andrey Nikishaev
echo "CHANGELOG"
echo ----------------------
git tag -l | sort -u -r | while read TAG ; do
    echo
    if [ $NEXT ];then
        echo [$NEXT]
    else
        echo "[Current]"
    fi
    GIT_PAGER=cat git log --no-merges --format=" * %s" $TAG..$NEXT
    NEXT=$TAG
done
FIRST=$(git tag -l | head -1)
echo
echo [$FIRST]
GIT_PAGER=cat git log --no-merges --format=" * %s" $FIRST

For creating changelog by tags, i used this script:

#!/bin/bash
# Author:Andrey Nikishaev
echo "CHANGELOG"
echo ----------------------
git tag -l | sort -u -r | while read TAG ; do
    echo
    if [ $NEXT ];then
        echo [$NEXT]
    else
        echo "[Current]"
    fi
    GIT_PAGER=cat git log --no-merges --format=" * %s" $TAG..$NEXT
    NEXT=$TAG
done
FIRST=$(git tag -l | head -1)
echo
echo [$FIRST]
GIT_PAGER=cat git log --no-merges --format=" * %s" $FIRST
舟遥客 2024-12-11 06:49:34

有一个非常有用的gem,输出是用markdown编写的,添加问题支持并通过标签分割提交

https:// /github.com/kebab-project/katip

There is a very useful gem, the output is written in markdown, add issue support and split commits by tags

https://github.com/kebab-project/katip

仅此而已 2024-12-11 06:49:34

只需使用标签名称作为提交说明符:git log --oneline --decorate v0.1.0

Just use the tag name as a commit specifier: git log --oneline --decorate v0.1.0

水波映月 2024-12-11 06:49:34

对 Creotiv 建议的脚本进行更新,以更好地对标签进行排序

#!/bin/bash
# Author:Andrey Nikishaev, Gunnar Lindholm
echo "CHANGELOG"
echo ----------------------
git for-each-ref --sort='*authordate' --format='%(tag)' refs/tags |tac |grep -v '^
 | while read TAG ; do
     echo
    if [ $NEXT ];then
        echo [$NEXT]
    else
        echo "[Current]"
    fi
    GIT_PAGER=cat git log --no-merges --format=" * %s" $TAG..$NEXT
    NEXT=$TAG
done
FIRST=$(git tag -l | head -1)
echo
echo [$FIRST]
GIT_PAGER=cat git log --no-merges --format=" * %s" $FIRST

An update to the script suggested by Creotiv to get better sorting of the tags

#!/bin/bash
# Author:Andrey Nikishaev, Gunnar Lindholm
echo "CHANGELOG"
echo ----------------------
git for-each-ref --sort='*authordate' --format='%(tag)' refs/tags |tac |grep -v '^
 | while read TAG ; do
     echo
    if [ $NEXT ];then
        echo [$NEXT]
    else
        echo "[Current]"
    fi
    GIT_PAGER=cat git log --no-merges --format=" * %s" $TAG..$NEXT
    NEXT=$TAG
done
FIRST=$(git tag -l | head -1)
echo
echo [$FIRST]
GIT_PAGER=cat git log --no-merges --format=" * %s" $FIRST
野却迷人 2024-12-11 06:49:34

我对原始脚本进行了修改。这可以正确处理版本标签。

#!/bin/bash
# Author:Andrey Nikishaev
echo "CHANGELOG"
echo ----------------------
git tag -l --sort=v:refname | tac | while read TAG ; do
    echo
    if [ $NEXT ];then
        echo [$NEXT]
    else
        echo "[Current]"
    fi
    GIT_PAGER=cat git log --no-merges --format=" * %s" $TAG..$NEXT
    NEXT=$TAG
done
FIRST=$(git tag -l --sort=v:refname | head -1)
echo
echo [$FIRST]
GIT_PAGER=cat git log --no-merges --format=" * %s" $FIRST

I came up with this modification of the original script. This handles version tags correctly.

#!/bin/bash
# Author:Andrey Nikishaev
echo "CHANGELOG"
echo ----------------------
git tag -l --sort=v:refname | tac | while read TAG ; do
    echo
    if [ $NEXT ];then
        echo [$NEXT]
    else
        echo "[Current]"
    fi
    GIT_PAGER=cat git log --no-merges --format=" * %s" $TAG..$NEXT
    NEXT=$TAG
done
FIRST=$(git tag -l --sort=v:refname | head -1)
echo
echo [$FIRST]
GIT_PAGER=cat git log --no-merges --format=" * %s" $FIRST
岁月蹉跎了容颜 2024-12-11 06:49:34

只需将 tagname 附加到您的命令中就可以了:)我喜欢使用 --graph 开关来可视化导致该标记的分支:)

Just append tagname to your command and you should be fine :) I like the --graph switch to visualize the branches that led to that tag :)

潇烟暮雨 2024-12-11 06:49:34

您可以使用 Git Changelog 命令行 来执行此操作:

npx git-changelog-command-line -std -tr v0.1.0 -tec "
# Changelog

Changelog for {{ownerName}} {{repoName}}.

{{#tags}}
## {{name}}
 {{#issues}}
  {{#hasIssue}}
   {{#hasLink}}
### {{name}} [{{issue}}]({{link}}) {{title}} {{#hasIssueType}} *{{issueType}}* {{/hasIssueType}} {{#hasLabels}} {{#labels}} *{{.}}* {{/labels}} {{/hasLabels}}
   {{/hasLink}}
   {{^hasLink}}
### {{name}} {{issue}} {{title}} {{#hasIssueType}} *{{issueType}}* {{/hasIssueType}} {{#hasLabels}} {{#labels}} *{{.}}* {{/labels}} {{/hasLabels}}
   {{/hasLink}}
  {{/hasIssue}}
  {{^hasIssue}}
### {{name}}
  {{/hasIssue}}

  {{#commits}}
**{{{messageTitle}}}**

{{#messageBodyItems}}
 * {{.}} 
{{/messageBodyItems}}

[{{hash}}](https://github.com/{{ownerName}}/{{repoName}}/commit/{{hash}}) {{authorName}} *{{commitTime}}*

  {{/commits}}

 {{/issues}}
{{/tags}}
"

You may use Git Changelog Command Line to do this:

npx git-changelog-command-line -std -tr v0.1.0 -tec "
# Changelog

Changelog for {{ownerName}} {{repoName}}.

{{#tags}}
## {{name}}
 {{#issues}}
  {{#hasIssue}}
   {{#hasLink}}
### {{name}} [{{issue}}]({{link}}) {{title}} {{#hasIssueType}} *{{issueType}}* {{/hasIssueType}} {{#hasLabels}} {{#labels}} *{{.}}* {{/labels}} {{/hasLabels}}
   {{/hasLink}}
   {{^hasLink}}
### {{name}} {{issue}} {{title}} {{#hasIssueType}} *{{issueType}}* {{/hasIssueType}} {{#hasLabels}} {{#labels}} *{{.}}* {{/labels}} {{/hasLabels}}
   {{/hasLink}}
  {{/hasIssue}}
  {{^hasIssue}}
### {{name}}
  {{/hasIssue}}

  {{#commits}}
**{{{messageTitle}}}**

{{#messageBodyItems}}
 * {{.}} 
{{/messageBodyItems}}

[{{hash}}](https://github.com/{{ownerName}}/{{repoName}}/commit/{{hash}}) {{authorName}} *{{commitTime}}*

  {{/commits}}

 {{/issues}}
{{/tags}}
"
寒尘 2024-12-11 06:49:34

使用 https://pypi.org/project/changelogfromtags/

pip install changelogfromtags && changelogfromtags

Using https://pypi.org/project/changelogfromtags/

pip install changelogfromtags && changelogfromtags
一曲琵琶半遮面シ 2024-12-11 06:49:34

对一个指定标签使用此命令

git for-each-ref --format '%(contents)' refs/tags/v0.1.0

v.0.1.0 更改为所需标签

Using this command for one specified tag

git for-each-ref --format '%(contents)' refs/tags/v0.1.0

change v.0.1.0 with desired tag

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