Skip to content

Instantly share code, notes, and snippets.

@fallroot
Created January 13, 2017 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fallroot/5300d4033385f0095e02e86fd405bde0 to your computer and use it in GitHub Desktop.
Save fallroot/5300d4033385f0095e02e86fd405bde0 to your computer and use it in GitHub Desktop.
Diff two branch what was not cherry-picked and cherry-pick with -c option
#!/bin/sh
while getopts "c" opt
do
case $opt in
c)
do_cherry_pick=true
;;
esac
done
shift $(($OPTIND - 1))
if [ $# -lt 1 ]
then
echo "Usage: $0 [-c] [upstream_branch] working_branch"
exit 1
fi
if [ $# -eq 1 ]
then
upstream_branch=$(git symbolic-ref --short HEAD)
working_branch=$1
else
upstream_branch=$1
working_branch=$2
fi
commits=$(git cherry -v $upstream_branch $working_branch | grep "^+" | sed "s/^+/#/" | $EDITOR)
if [ "$do_cherry_pick" = true ]
then
if [ $# -gt 1 ]
then
git checkout $upstream_branch
fi
echo "$commits" | grep -v "^#" | sed "s/ .*//" | xargs git cherry-pick
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment