Reputation: 189
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 ...
Upvotes: 0
Views: 183
Reputation: 30858
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.
Update:
The commits you want to pick are reachable from one or more branches or tags. Branches and tags belong to refs. In most cases you can't fetch a random single commit, unless the remote repository allows it. In order to get the commits into your current repository, you need to fetch the refs from the other repository. Suppose the commits are from the branch foo
, the history is A-B-C-D-E-F-G
and you want to pick C, D, and E. You need to run git fetch origin foo
before you cherry-pick these commits to the current branch. You can specify the commits in git cherry-pick
, either one by one or in a range by X..Y
or maybe X...Y
:
git cherry-pick C D E -x
git cherry-pick B..E -x
The graph of foo
may be more complicated than this simple example, but you can always find a proper way to specify them all.
Upvotes: 3