Binary Static

How to Convert Git Log to ChangeLog

Posted in Coding, Linux by Chris on February 18, 2010

Git Logo

This is quite a useless endeavor, of course.  Since every fork from Git contains the whole change history, GNU-style ChangeLogs are pretty obsolete.  However, if you want to distribute your source files in a traditional tarball, you might want to add a ChangeLog file – and you might want it to look like the ones in the GNU coding standard.  This is where my shell script comes in, which I wrote yesterday while doing some serious procrastination:


#!/bin/sh
# Convert git log to GNU-style ChangeLog file.
# (C) Chris
if test -d ".git"; then
    git log --date-order --date=short | \
    sed -e '/^commit.*$/d' | \
    awk '/^Author/ {sub(/\\$/,""); getline t; print $0 t; next}; 1' | \
    sed -e 's/^Author: //g' | \
    sed -e 's/>Date:   \([0-9]*-[0-9]*-[0-9]*\)/>\t\1/g' | \
    sed -e 's/^\(.*\) \(\)\t\(.*\)/\3    \1    \2/g' > ChangeLog
    exit 0
else
    echo "No git repository present."
    exit 1
fi

This code goes conveniently in a Makefile template for Autotools, so you can create the ChangeLog on the fly, include it in the distribution tarball and have it unlinked afterwards. Again, there’s no need to have a ChangeLog lie around with Git.

About these ads
Tagged with: , , , ,

2 Responses

Subscribe to comments with RSS.

  1. Marcio Andrey Oliveira said, on April 17, 2011 at 12:13 am

    Hi. Very nice script but there is two small differences between ChagneLog generated by your script and what is at the GNU coding standard:

    1 – Date comes before the author data.
    2 – Between date and author data there are two spaces and not a tab.

    I changed your script a little so it correct these to minor differences:

    sed -e ‘s/\(.*\)>Date: \([0-9]*-[0-9]*-[0-9]*\)/\2 \1>/g’ | \

  2. ao2it said, on September 23, 2011 at 12:13 pm

    Hi,

    I ended up using this to generate GNU ChangeLog files[1]:
    git –no-pager log –format=”%ai %aN %n%n%x09* %s%d%n” > ChangeLog

    Regards,
    Antonio

    [1] http://www.gnu.org/s/libtool/manual/emacs/Format-of-ChangeLog.html


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: