Skip to content

Instantly share code, notes, and snippets.

@prati0100
Last active March 17, 2021 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prati0100/c0492772d7c94e793c657a824c00ea63 to your computer and use it in GitHub Desktop.
Save prati0100/c0492772d7c94e793c657a824c00ea63 to your computer and use it in GitHub Desktop.
Add "commit <hash> upstream" to the commit message by looking at the upstream branch for matching commits
#!/usr/bin/env bash
# SPDX-License-Identifier: MIT
# Example usage: mark_backport.sh upstream/master
#
# If the upstream branch has too many commits this can be very slow. In this
# case, pass other arguments to limit the git log to contain all your commits.
# For example, you are use '--author' or pathspecs. Example with pathspecs:
# mark_backport.sh upstream/master -- drivers/spi
if test $# -lt 1; then
echo "Not enough arguments"
exit 1
fi
patchid=$(git show HEAD | git patch-id --stable | awk '{print $1}')
# This usually takes very long to do on large repos like Linux. Better pass some
# other parameters to limit history like author name or pathspec if possible.
upstream_hash=$(git log -p --full-diff $@ | git patch-id --stable | grep -m 1 $patchid | awk '{print $2}')
if test -z $upstream_hash; then
exit 1
fi
tmp=$(mktemp)
git show --pretty=%s --no-patch HEAD > $tmp
echo "" >> $tmp
echo "commit $upstream_hash upstream." >> $tmp
echo "" >> $tmp
git show --pretty=%b --no-patch HEAD >> $tmp
git commit --amend --no-edit -F $tmp
rm $tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment