Git - 合并来自不同存储库的分支
我希望这看起来并不明显。我有两个 git 存储库。我们决定将第一个存储库中的一个分支拆分为 git 子模块。现在我一直在使用这个子模块,但是人们一直在将第一个存储库的提交推送到制作为子模块的分支中。
如何将第一个存储库中的分支的更改合并到新创建的第二个存储库中? (我们现在用作子模块)
我尝试将另一个遥控器添加到第二个存储库中并合并该分支,使用:
git remote add otherOrigin [email protected]:originalRepo.git
git merge otherOrigin originalBranch
但是我得到:
fatal: 'otherOrigin' does not point to a commit
谢谢
I hope this does not seem to obvious. I have two git repository. We decided to split one branch from the first repoistry into a git sub module. Now I have been using this sub module, however people have been pushing commits to the first repository into the branch that was made into a sub module.
How can I merge the changes from the branch in the first repository into newly created second repository? (Which we now use as the sub-module)
I have tried adding another remote into the second repo and merging that branch across, using:
git remote add otherOrigin [email protected]:originalRepo.git
git merge otherOrigin originalBranch
However I get:
fatal: 'otherOrigin' does not point to a commit
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
克隆您的存储库。现在使用 filter-branch 来保留对子模块中应有内容的更改。将此存储库添加为子模块的远程版本。从新的远程获取分支。使用 git rebase --root --onto 来将更改“放置”到子模块历史记录中的某个点。
希望这有帮助。
clone your repository. Now use filter-branch to just keep the changes to what should be in your submodule. add this repo as a remote of your submodule. fetch the branch from that new remote. Use
git rebase --root --onto
to "place" the changes to some point in the history of your submodule.Hope this helps.
如果对于给定的分支(在 Repo1 中拆分为子模块,同时保留在 Repo2 中)的两个存储库最初具有共同历史,那么理论上应该是可能的, to:
但如果您必须定期重复该过程(除非您可以编写脚本),那么这很快就会成为一种阻力。
If the two repos, for the given branch (the one split as a sub-module in Repo1, while being kept in Repo2), initially have a common history, then it should be possible, in theory, to:
But that can quickly become a drag if you have to repeat that process on a regular basis (unless you can script it).