Skip to content

Instantly share code, notes, and snippets.

@pirtleshell
Created March 22, 2018 21:41
Show Gist options
  • Save pirtleshell/7ff5c164796f001dd16ee5a888e83604 to your computer and use it in GitHub Desktop.
Save pirtleshell/7ff5c164796f001dd16ee5a888e83604 to your computer and use it in GitHub Desktop.
A quick script to git cherry-pick multiple commits to the current branch. Great for setting up commits in an order that makes sense for things like squashing non-sequential commits
#! /bin/bash
# list all commit refs, one per line.
# edit these before running:
COMMITS='5e5138a8a2
f190eb81ff
9462a4ab68'
# if you have all your commit refs listed in a file,
# do something like this:
# COMMITS=$(cat /path/to/commits/list)
for commit in $COMMITS; do
sleep 1
echo picking $commit
git cherry-pick $commit
if [ $? -ne 0 ]; then
echo commit $commit failed
echo resolve any conflicts, commit, and try again
exit 1
fi
done
echo 'done!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment