Skip to content

Instantly share code, notes, and snippets.

@SarasArya
Created October 12, 2017 07:43
Show Gist options
  • Save SarasArya/1b9eb3683e4740d7ba19ec926c3dc3b3 to your computer and use it in GitHub Desktop.
Save SarasArya/1b9eb3683e4740d7ba19ec926c3dc3b3 to your computer and use it in GitHub Desktop.
This gist lists the cherry pick by author and stores in a file and apply it on a branch
#!/usr/bin/env bash
if [ -z ${1} ]
then
echo "Enter first argument which is author name";
exit
fi
if [ -z {$2} ]
then
echo "enter second argument which is in which branch you want these commits to go"
exit
fi
echo "Cherry picking commit for user ${1} from branch $(git symbolic-ref --short -q HEAD) will put into ${2}" ;
git log --committer="saras.arya@rentomojo.com" --format=format:%H > cherry-pick.txt
git checkout ${2}
for commit in $(cat cherry-pick.txt) ; do
hash=$(echo ${commit} | cut -d$'\t' -f 1)
printf "${hash}\n"
git cherry-pick ${hash}
done
@biemster
Copy link

biemster commented Feb 6, 2023

You might want to consider on line 17 tac instead of cat? That way it will apply the changes in the order the developer did.

@SarasArya
Copy link
Author

@biemster that is a very interesting point, for that matter. I didn't even know there was a command called tac.

@biemster
Copy link

biemster commented Feb 7, 2023

I just used this gist to save a week of my work on a branch I wrecked (thanks for this!), but it only managed to successfully apply the hashes in the correct order, so using tac. Thanks again!

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