Git 更改日志:如何将所有更改更改为特定标签?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7387612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:59:30  来源:igfitidea点击:

Git changelog: how to get all changes up to a specific tag?

gitloggingchangelog

提问by Luwe

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.0and for instance would like all commits up to tag v0.1.0.

是否有一种简单的方法或命令可以将所有 git 提交都提交到特定标签以生成项目的自动更改日志?我总是用一个版本号来标记我的 git repos,v0.1.0例如,我希望所有提交都达到 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)

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

For instance:

例如:

$ git log --oneline --decorate

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

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

回答by Mark Longair

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 logallows also allows you to restrict the commits shown in any of the ways that git rev-listunderstands, so if you only wanted to see the changes between v0.0.9and v0.1.0you could also do:

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

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,它对每个作者的贡献进行分组和总结。尝试,例如:

git shortlog v0.1.0

回答by Andrey Nikishaev

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

回答by FORTRAN

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

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

回答by rderoldan1

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

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

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

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

回答by Lev

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

回答by flob

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

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

回答by Alexander Poluektov

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

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

回答by Tomas Bjerre

You may use Git Changelog Command Lineto do this:

您可以使用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}}
"

回答by Constantin De La Roche

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

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

pip install changelogfromtags && changelogfromtags