How to pick commits from another git repository, and keep or record the original hashes

With reference to this thread: Is it possible to cherry-pick a commit from another git repository?

.. and this answer provided in there (which is what I need):

$ git --git-dir=../<some_other_repo>/.git \
 format-patch -k -1 --stdout <commit SHA> |
 \ git am -3 -k

Is there a possible variation of this which can automatically also record (add to the commit messages?) the relevant git hashes from where I'm patching from to where I'm applying to?

Manually editing is possible but very tedious for +100 commits ...

1 answer

  • answered 2018-07-12 07:51 ElpieKay

    git fetch <path_to_some_other_repo> <ref_that_has_the_commit>
    git cherry-pick <the_commit> -x
    

    -x appends a line that says "(cherry picked from commit …​)" to the original commit message. But it doesn't record which repository the commit is from.