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

10

28

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.

Knock answered 12/9, 2011 at 12:10 Comment(1)
Relevant to your interests: Pimp My Changelog, a Ruby script to do this. github.com/pcreux/pimpmychangelogTurbit
C
50

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
Caracas answered 12/9, 2011 at 12:14 Comment(5)
Thanks for your elaborate answer :) This is exactly what I wanted.Knock
To display commits after a specific tag you can use git log --oneline --decorate v0.1.0..Confute
How to copy the log after running the git command i.e. git log --oneline --decorate ?Fernanda
How to save it in a file?Jeanett
@MateusViccari You would use output redirection with >, e.g. git log --oneline --decorate v0.0.9..v0.1.0 > changes.txtCaracas
F
8

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
Flaw answered 9/1, 2012 at 15:53 Comment(1)
If your tags are versions on the form x.y.z, add the -V flag to sort to correctly sort versions like 1.0.9, 1.0.10, etc.Cladoceran
I
4

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

Iodometry answered 4/9, 2013 at 16:20 Comment(0)
S
3

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

Submerge answered 12/9, 2011 at 12:15 Comment(0)
M
3

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
Mote answered 27/3, 2012 at 6:31 Comment(0)
C
3

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
Cybill answered 1/3, 2018 at 10:44 Comment(0)
S
2

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 :)

Suckle answered 12/9, 2011 at 12:13 Comment(0)
S
0

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}}
"
Smithson answered 30/5, 2019 at 13:32 Comment(0)
S
0

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

pip install changelogfromtags && changelogfromtags
Scaife answered 6/1, 2020 at 19:13 Comment(0)
U
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

Ulla answered 14/4, 2022 at 7:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.