Skip to content

Instantly share code, notes, and snippets.

@tueda
Last active April 11, 2023 10:49
Show Gist options
  • Save tueda/62efdd8524e57c91cd8c770dfe98c9dd to your computer and use it in GitHub Desktop.
Save tueda/62efdd8524e57c91cd8c770dfe98c9dd to your computer and use it in GitHub Desktop.
Try "git cherry-pick" in a range of commits. #shell #git #cherry-pick
#!/bin/sh
#
# @file auto-cherry-pick.sh
#
# Usage:
# auto-cherry-pick.sh ref1...ref2:
#
set -eu
output=auto-cherry-pick.log
rm -f $output
git log --oneline --reverse --pretty=format:%H "$1" | while IFS= read -r long_hash; do
short_hash=$(git log --oneline --pretty=format:%h "$long_hash")
subject=$(git log --oneline --pretty=format:%s "$long_hash")
subject=
if git show --summary "$long_hash" | grep -q ^Merge; then
echo "$short_hash MERGE $subject" >>$output
else
if git cherry-pick -X ignore-all-space "$long_hash"; then
echo "$short_hash SUCEEDED $subject" >>$output
else
if git diff --quiet; then
echo "$short_hash EMPTY $subject" >>$output
else
echo "$short_hash CONFLICT $subject" >>$output
fi
git cherry-pick --abort
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment