Skip to content

Instantly share code, notes, and snippets.

@richardlopes-daitangroup
Created April 24, 2018 13:09
Show Gist options
  • Save richardlopes-daitangroup/b8e8ad228a47121bbd08ac3aca1ab163 to your computer and use it in GitHub Desktop.
Save richardlopes-daitangroup/b8e8ad228a47121bbd08ac3aca1ab163 to your computer and use it in GitHub Desktop.
Cherry pick a list of commit hashes
#!/usr/bin/env bash
# Cherry pick a list of commit hashes coming from a file
LIST_FILE="${1}"
if [ "${LIST_FILE}" = "" ] ; then
echo "Pleas give path to commit list file!"
echo "Usage: cherry-pick-list <file/to/picklist>"
exit 1
fi
echo "Cherry-picking all commits from file ${LIST_FILE} ..."
COUNT=1
IFS=$'\n'
for commit in $(cat "${LIST_FILE}") ; do
hash=$(echo ${commit} | cut -d$'\t' -f 1)
echo -n "cherry picking ${hash} ... "
git cherry-pick "${hash}"
if [ $? -eq 0 ] ; then
echo "done."
else
echo "There are conflicts to resolve!"
read -p "Press [ENTER] key if you have resolved the conflicts and to continue ..."
fi
COUNT=$((COUNT+1))
done
echo "Maybe you want to rebase: git rebase -i HEAD~${COUNT}"
# Get all commit hashes into ~/commits file
git log SELF-193 --grep=SELF-193 --author=Richard --pretty=%h --reverse > ~/commits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment