如何将特定版本之间的分支推送到另一个仓库?
How to push a branch between a certain versions to another repo?
我知道我可以通过 运行 这个命令将一个 git 项目(说 'old')的一个分支移植到另一个项目(说 'new'):
cd old # location of the 'old' repo
git push git:git@github.com:dude/new.git a-branch
但是我不想将分支的所有历史记录推送到新的 git 项目。我只想在此分支中包含一部分提交。
我该怎么做?
您只需指定要将该分支限制为的 SHA1:
git push git:git@github.com:dude/new.git <SHA1>:abranch
<SHA1>
之前的所有提交都将被推送到 new.git
存储库上的远程分支“abranch
”。
参见示例:
- "Git push up to a certain commit "
- "git - pushing specific commit" (which also suggests
git cherry-pick
如果你只想要分支内的一个范围,而不是 'all commits up to and including <SHA1>
)
如果您只想推送历史的一个子集,您必须创建一个仅包含您要推送的提交子集的分支。因此,根据您当前的
创建一个新分支
git checkout -b subsetOfCommits
比在交互模式下变基。
git rebase -i firstCommitYouWantToChange
使用 rebase 交互式编辑器和 squash
、fixup
,移动或删除提交。
最后将该分支推到你想要的任何地方。
我知道我可以通过 运行 这个命令将一个 git 项目(说 'old')的一个分支移植到另一个项目(说 'new'):
cd old # location of the 'old' repo
git push git:git@github.com:dude/new.git a-branch
但是我不想将分支的所有历史记录推送到新的 git 项目。我只想在此分支中包含一部分提交。
我该怎么做?
您只需指定要将该分支限制为的 SHA1:
git push git:git@github.com:dude/new.git <SHA1>:abranch
<SHA1>
之前的所有提交都将被推送到 new.git
存储库上的远程分支“abranch
”。
参见示例:
- "Git push up to a certain commit "
- "git - pushing specific commit" (which also suggests
git cherry-pick
如果你只想要分支内的一个范围,而不是 'all commits up to and including<SHA1>
)
如果您只想推送历史的一个子集,您必须创建一个仅包含您要推送的提交子集的分支。因此,根据您当前的
创建一个新分支git checkout -b subsetOfCommits
比在交互模式下变基。
git rebase -i firstCommitYouWantToChange
使用 rebase 交互式编辑器和 squash
、fixup
,移动或删除提交。
最后将该分支推到你想要的任何地方。