仅将一些提交推送到另一个 git 存储库

Push only some commits to another git repository

我有两个远程 originanother 存储库,例如,在 origin:master 存储库上提交历史记录:

A - B - C - D - E - F

another 是空回购。

只需要将最后两个提交 E - F 推送到 another:master 即:

origin:master: A - B - C - D - E - F
another:master: E - F 

在没有变基或其他东西的情况下推入这两个遥控器后,我如何才能做到这一点?

您需要一个 git 历史记录,其中包含初始 empty commit 和两个分支:一个(您当前的 master)指向 F,另一个指向空提交。

检查指向空提交的分支,cherry-pick EF,并将此分支推送到您的 another 远程。当您在 another 存储库中进行所需的更改时,您只需 cherry-pick 它们就可以了。

因此,在创建初始提交后:

git checkout -b another-branch <<SHA of empty initial commit>>
git cherry-pick <<SHA of E>>
git cherry-pick <<SHA of F>>
git push another another-branch