Skip to content

Instantly share code, notes, and snippets.

@xinan
Last active October 16, 2015 04:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save xinan/42669b49153af52919b2 to your computer and use it in GitHub Desktop.
Save xinan/42669b49153af52919b2 to your computer and use it in GitHub Desktop.
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
Copy link

jszuppe commented Sep 8, 2015

Thanks for this script.

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

@xinan
Copy link
Author

xinan commented Sep 8, 2015

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

@yousefhamza
Copy link

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

@xinan
Copy link
Author

xinan commented Sep 9, 2015

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

@aoifeboyle
Copy link

@xinan Thanks for this. Very helpful!

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