Add a cherry-pick-merge command
This is rarely needed, but very handy when it is actually needed. Do
use with caution.
Change-Id: I81792147da3a2fb358148ca3d6f18ba878410f84
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/tools/cherry-pick-merge.sh b/tools/cherry-pick-merge.sh
new file mode 100755
index 0000000..547fecf
--- /dev/null
+++ b/tools/cherry-pick-merge.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+#
+# The script replays a merge based on its first parent.
+# This will create a new merge with the same message and second parent, but with
+# its first parent as the current commit.
+#
+# It is advised for now to backup your repo before running this command and
+# make sure the git history is what you want until we use it more.
+
+set -e
+set -o pipefail
+
+COMMIT=$1
+
+MESSAGE=$(git show -s --format=%B ${COMMIT})
+
+git cherry-pick -m1 ${COMMIT}
+git reset --soft HEAD~
+echo ${COMMIT}^2 > .git/MERGE_HEAD
+git commit --message="${MESSAGE}"