Created
January 24, 2019 19:45
-
-
Save paulscott/878ba5c61cd3bf2a5cfaa058e967f47a to your computer and use it in GitHub Desktop.
generate a changelog from the git commit messages between the current branch and the most recent ancestor tag, or between two named refs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# gives a changelog from the most recent tag to the current HEAD, with blank lines removed | |
currentHead='HEAD' | |
lastTag=$(git describe --tags --abbrev=0 2>/dev/null) | |
if [ -z "${lastTag}" ]; then | |
fromType="initial commit" | |
lastTag=$(git rev-list HEAD --max-parents=0 | cut -c 1-10) | |
fi | |
# if no args, $buildBranch..$currentBranch | |
# if one arg, $1..$currentBranch | |
# if twho args, $1..$2 | |
fromBranch=${1-$lastTag} | |
toBranch=${2-$currentHead} | |
fromMsg="${fromType-$([ -z "${1}" ] && echo 'tag' || echo '')} ${fromBranch}" | |
echo "Change log from ${fromMsg} to ${toBranch}:" | |
git log "${fromBranch}..${toBranch}" --pretty='format:- %s (%aN) %n %b' | grep '[^[:space:]]' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment