Created
November 14, 2012 09:08
-
-
Save jeffnem/4071114 to your computer and use it in GitHub Desktop.
git commit listing from http://bertrandbenoit.blogspot.com/2012/01/git-alias-to-get-my-last-commits.html
This file contains 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 | |
# | |
# Author: Bertrand BENOIT | |
# Version: 1.1 | |
# Description: lists last commit of current author according to specified (optional) branch and count. | |
# To use this script, create a git alias. | |
# git config --global alias.mc '!/path/to/gitListMyLastCommits.sh' | |
DEFAULT_COMMIT_COUNT=5 | |
export GIT_PAGER=cat | |
# Manages command line options. | |
# - case 1: 2 specified arguments | |
# - case 2: 1 specified argument [-] (with optional negative sign) | |
# - case 3: no specified arguments -> work on current branch, with 5 last commits of author | |
if [ $# -gt 2 ] || [ $( echo "$@" |grep -cwE "(-h|--help)" ) -gt 0 ]; then | |
echo -e "usage: git " | |
echo -e "The branch can be ommitted" | |
echo -e "The commit count can be ommitted (default: $DEFAULT_COMMIT_COUNT will be shown)" | |
echo -e "If only one argument is given, it is regarded as commit count, so you can NOT only specify a branch, without a commit count" | |
exit 1 | |
fi | |
# Ensures there is a negative sign for last argument, if needed. | |
if [ $# -eq 0 ]; then | |
arguments="-$DEFAULT_COMMIT_COUNT" | |
else | |
arguments=$( echo "$@" |sed -e 's/^\([0-9][0-9]*\)$/-\1/;s/[ ]\([0-9][0-9]*\)$/ -\1/' ) | |
fi | |
authorInfo=$( git config --get user.email ) | |
[ -z "$authorInfo" ] && echo "WARNING: unable to define author information, ensure you have configured user.email." >&2 && exit 1 | |
echo -e "Looking last commits of author '$authorInfo', with arguments: $arguments" | |
git log --format='%h - %cd - %s' --date=short --author="$authorInfo" $arguments | |
echo -ne "\nOrdered commit short SHA1 chain (can be used with cherry-pick): " | |
git log --format='%h - %cd - %s' --date=short --author="$authorInfo" $arguments |awk '{print $1}' |sed -e 's/$/ /g' |tac |tr -d '\n' | |
echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment