Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are some good ways to manage a changelog using Git? [closed]

People also ask

What is a git changelog?

A changelog is a file that shares a chronologically ordered list of the changes you've made on your project. It's often organized by the version with the date followed by a list of added, improved, and removed features.

What is a changelog entry?

A changelog is a log or record of all notable changes made to a project. The project is often a website or software project, and the changelog usually includes records of changes such as bug fixes, new features, etc. Some open-source projects include a changelog as one of the top-level files in their distribution.


This was in 2015, but for the sake of future searchers, it's now possible to generate gorgeous logs with:

git log --oneline --decorate

Or, if you want it even prettier (with color for the terminal):

git log --oneline --decorate --color

Piping that output to ChangeLog is what I currently use in all my projects, and it's simply amazing.


You can use some flavor of git log to help you out:

git log --pretty=%s                 # Only prints the subject

If you name your branches nicely, so that a merge to master shows up as something like "Merged branch feature-foobar", you can shorten things by only showing that message, and not all the little commits that you merged, which together form the feature:

git log --pretty=%s --first-parent  # Only follow the first parent of merges

You might be able to augment this with a script of your own, which could do things like strip out the "Merged branch" bits, normalize formatting, etc. At some point you have to write it yourself though, of course.

Then you could create a new section for the changelog once per version:

git log [opts] vX.X.X..vX.X.Y | helper-script > changelogs/X.X.Y

And commit that in your version release commit.

If your problem is that those commit subjects aren't anything like what you'd want to put in a changelog, you pretty much have two options: keep doing everything manually (and try to keep up with it more regularly instead of playing catch-up at release time), or fix up your commit message style.

One option, if the subjects aren't going to do it for you, would be to place lines like "change: added feature foobar" in the bodies of your commit messages, so that later you could do something like git log --pretty=%B | grep ^change: to grab only those super-important bits of the messages.

I'm not entirely sure how much more than that Git could really help you create your changelogs. Maybe I've misinterpreted what you mean by "manage"?


TL;DR: You might want to check gitchangelog's own changelog or the ASCII output that generated the previous.

If you want to generate a changelog from your Git history, you'll probably have to consider:

  • the output format. (Pure custom ASCII, Debian changelog type, Markdown, REST, etc.)
  • some commit filtering (you probably don't want to see all the typos or cosmetic changes getting in your changelog)
  • some commit text wrangling before being included in the changelog. (Ensuring normalization of messages as having a first letter uppercase or a final dot, but it could be removing some special markup in the summary also.)
  • is your Git history compatible?. Merging and tagging is not always so easily supported by most of the tools. It depends on how you manage your history.

Optionally, you might want some categorization (new things, changes, bugfixes, etc.).

With all this in mind, I created and used gitchangelog. It's meant to leverage a Git commit message convention to achieve all of the previous goals.

Having a commit message convention is mandatory to create a nice changelog (with or without using gitchangelog).

Commit message convention

The following are suggestions to what might be useful to think about adding in your commit messages.

You might want to separate roughly your commits into big sections:

  • by intent (for example: new, fix, change, etc.)
  • by object (for example: doc, packaging, code, etc.)
  • by audience (for example: dev, tester, users, etc.)

Additionally, you could want to tag some commits:

  • as "minor" commits that shouldn't get outputted to your changelog (cosmetic changes, a small typo in comments, etc.)
  • as "refactor" if you don't really have any significant feature changes. Thus this should not also be part of the changelog displayed to final user for instance, but it might be of some interest if you have a developer changelog.
  • you could tag also with "API" to mark API changes or new API stuff...
  • ...etc...

Try to write your commit message by targeting users (functionality) as often as you can.

Example

This is the standard git log --oneline to show how this information could be stored::

* 5a39f73 fix: encoding issues with non-ASCII characters.
* a60d77a new: pkg: added ``.travis.yml`` for automated tests.
* 57129ba new: much greater performance on big repository by issuing only one shell command for all the commits. (fixes #7)
* 6b4b267 chg: dev: refactored out the formatting characters from Git.
* 197b069 new: dev: reverse ``natural`` order to get reverse chronological order by default. !refactor
* 6b891bc new: add UTF-8 encoding declaration !minor

So if you've noticed, the format I chose is:

{new|chg|fix}: [{dev|pkg}:] COMMIT_MESSAGE [!{minor|refactor} ... ]

To see an actual output result, you could look at the end of the PyPI page of gitchangelog.

To see a full documentation of my commit message convention, you can see the reference file gitchangelog.rc.reference.

How to generate an exquisite changelog from this

Then, it's quite easy to make a complete changelog. You could make your own script quite quickly, or use gitchangelog.

gitchangelog will generate a full changelog (with sectioning support as New, Fix...) and is reasonably configurable to your own committing conventions. It supports any type of output thanks to templating through Mustache, Mako templating, and has a default legacy engine written in raw Python; all current three engines have examples of how to use them and can output changelogs as the one displayed on the PyPI page of gitchangelog.

I'm sure you know that there are plenty of other git log to changelog tools out there also.

DISCLAIMER: I'm the author of gitchangelog of which I'll be speaking in the following.


A more to-the-point changelog:

git log --since=1/11/2011 --until=28/11/2011 --no-merges --format=%B