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

前端 未结 9 1835
长情又很酷
长情又很酷 2021-01-31 09:37

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 lik

相关标签:
9条回答
  • 2021-01-31 10:13

    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}}
    "
    
    0 讨论(0)
  • 2021-01-31 10:14

    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
    
    0 讨论(0)
  • 2021-01-31 10:14

    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
    
    0 讨论(0)
  • 2021-01-31 10:19

    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

    0 讨论(0)
  • 2021-01-31 10:19

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

    0 讨论(0)
  • 2021-01-31 10:22

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

    pip install changelogfromtags && changelogfromtags
    
    0 讨论(0)
提交回复
热议问题