Consider the following sequence of commands:
git replace --graft <sha> <new_parent_sha>
new_commit_sha="$(git show-ref refs/replace/<sha> | awk '{print $1}')"
git update-ref -d refs/replace/<sha>
The end result is that we have a commit (new_commit_sha) with new parents, that is identical to the original commit (same tree, same message, same author and committer, author date, commit date) except that the parents are different.
Is there a more direct way to achieve the same effect of duplicating a commit with replaced parents without first creating a replace
ref and then deleting it?
I looked at git-commit-tree
but did not see an option to take most commit properties from a source commit.
I also played with git cherry-pick
but that tries to apply a patch which can run into conflicts and results in a different tree if the parent is different. I am trying to produce a commit with exactly the same tree (and other properties).