Git - 合并来自不同存储库的分支

发布于 2024-11-16 10:37:40 字数 544 浏览 2 评论 0原文

我希望这看起来并不明显。我有两个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

℡Ms空城旧梦 2024-11-23 10:37:41

克隆您的存储库。现在使用 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.

阳光下慵懒的猫 2024-11-23 10:37:40

如果对于给定的分支(在 Repo1 中拆分为子模块,同时保留在 Repo2 中)的两个存储库最初具有共同历史,那么理论上应该是可能的, to:

  • 将 Repo2 中的分支拆分为单独的存储库
  • 添加该单独的存储库作为当前子模块存储库的远程
  • 尝试并从那里执行合并。

但如果您必须定期重复该过程(除非您可以编写脚本),那么这很快就会成为一种阻力。

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:

  • split the branch in Repo2 as an individual repo
  • add that individual repo as a remote of the current submodule repo
  • try and perform the merge from there.

But that can quickly become a drag if you have to repeat that process on a regular basis (unless you can script it).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文