Created
January 13, 2017 10:35
-
-
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
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/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