Skip to content

Instantly share code, notes, and snippets.

@therightstuff
Last active March 24, 2020 18:35
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 therightstuff/1983aaf8bf0c7feec8542df15cac5548 to your computer and use it in GitHub Desktop.
Save therightstuff/1983aaf8bf0c7feec8542df15cac5548 to your computer and use it in GitHub Desktop.
add a parent commit to an existing git commit
#!/bin/bash
# add a parent commit to the specified commit, ideal
# for establishing the other parent of a squashed merge
# lifted from https://stackoverflow.com/a/41243690/2860309
# usage: ./add_parent.sh TARGET_COMMIT_ID NEW_PARENT_COMMIT_ID
set -ex
target_commit=$1
additional_parent=$2
git replace --graft $target_commit \
$(git show --pretty=%P $target_commit | head -n1) \
$additional_parent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment