27

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

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

例如:

$ git log --oneline --decorate

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

4

9 回答 9

47

你可以这样做:

git log --oneline --decorate v0.1.0

...显示直到并包括 v0.1.0 的每个提交。当然,git logallows 还允许您限制以任何可以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
于 2011-09-12T12:14:56.120 回答
7

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

#!/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
于 2012-01-09T15:53:03.827 回答
4

有一个非常有用的gem,输出是用markdown写的,添加问题支持和按标签拆分提交

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

于 2013-09-04T16:20:45.340 回答
3

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
于 2012-03-27T06:31:47.620 回答
3

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

#!/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
于 2018-03-01T10:44:17.810 回答
2

只需附加tagname到您的命令,您就应该没问题 :) 我喜欢这个--graph开关来可视化导致该标签的分支 :)

于 2011-09-12T12:13:26.357 回答
2

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

于 2011-09-12T12:15:48.037 回答
0

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

pip install changelogfromtags && changelogfromtags
于 2020-01-06T19:13:06.293 回答
0

您可以使用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}}
"
于 2019-05-30T13:32:58.027 回答