Skip to content

Instantly share code, notes, and snippets.

@IchHabRecht
Last active December 22, 2015 19:49
Show Gist options
  • Save IchHabRecht/6522551 to your computer and use it in GitHub Desktop.
Save IchHabRecht/6522551 to your computer and use it in GitHub Desktop.
Writes a ChangeLog depending on your git commits
#!/bin/sh
WRITE=false
FILE="ChangeLog"
GITPATH="master..HEAD"
while [ "$1" != "" ]; do
case $1 in
-c )
GITPATH=""
;;
-w )
WRITE=true
;;
-f )
shift
FILE="$1"
;;
* )
GITPATH="$1"
;;
esac
shift
done
if `git branch --no-color | grep -q '^\*'`; then
OUTPUT=""
HEAD=""
BRANCH=`git branch --no-color | grep '^\*' | grep -v 'no branch' | sed 's/^* //g' | sed 's/.*\///g' | grep '^[0-9][0-9.]'`
if [ "$BRANCH" != "" ]; then
DATE=`date +%Y-%m-%d`
DIR=${PWD##*/}
USER=`git config --get user.name`
HEAD="$DATE [RELEASE] Release of $DIR $BRANCH ($USER)"$'\n'
fi
LOG=`git log --pretty=format:"%ad %h %s (%an)" --date=short --no-merges $GITPATH`
if [ "$LOG" != "" ]; then
OUTPUT=$HEAD$LOG$'\n'$'\n';
fi
if [ -f $FILE ]; then
OUTPUT=$OUTPUT"`cat $FILE`"
fi
if $WRITE; then
echo "$OUTPUT" > $FILE
OUTPUT=$OUTPUT$'\n'$'\n'"File $FILE was written."
fi
echo "$OUTPUT"
fi
# USAGE
# git write-changelog [-c] [-w] [-f <filename>] [<path>]
# git write-changelog [-w] [-f ChangeLog] [master..HEAD]
# -c: Write log for whole changes
# -w: Write log to file
# -f <filename>: Name of changelog file
# path: path for git log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment