Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This is a simple shell script to extract commits by a specified author in a git repository and format them as numbered patches. It is useful for GSoC code submission.
if ! [[ $# -eq 1 || $# -eq 2 || $# -eq 4 ]]; then
echo "Usage: $0 <author> [<start_date> <end_date>] [output_dir]"
echo "Example: $0 xinan@me.com 2015-05-25 2015-08-21 ./patches"
exit
fi
author=$1
if [ $# -gt 3 ]; then
output_dir=$4
elif [ $# -eq 2 ]; then
output_dir=$2
else
output_dir="./"
fi
if [ $# -gt 2 ]; then
start=$2
end=$3
else
start="2015-05-25"
end="2015-08-21"
fi
counter=0
for i in `git log --author=$author --since=$start --until=$end --pretty=oneline | sed 's/ .*//' | tail -r`
do
counter=$((counter+1))
git format-patch -M -C -1 --start-number $counter $i -o $output_dir
done
@jszuppe

This comment has been minimized.

Copy link

@jszuppe jszuppe commented Sep 8, 2015

Thanks for this script.

tail -r works only on BSD, for GNU/Linux tac can be used instead.

@xinan

This comment has been minimized.

Copy link
Owner Author

@xinan xinan commented Sep 8, 2015

@haaHh Thanks for the info! I didn't know that. Learnt something 😄

@yousefhamza

This comment has been minimized.

Copy link

@yousefhamza yousefhamza commented Sep 9, 2015

my author name had spaces so that was an issue, fixed with double quotes on author attribute in 'git log'

@xinan

This comment has been minimized.

Copy link
Owner Author

@xinan xinan commented Sep 9, 2015

@yousefhamza Oh I did not consider that 😅 You can always use email address as author by the way.

@aoifeboyle

This comment has been minimized.

Copy link

@aoifeboyle aoifeboyle commented Sep 29, 2015

@xinan Thanks for this. Very helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment