将git子模块中的更改推送到主模块,但不推送到子模块 [英] Push changes in git submodule to main module but not to submodule

查看:89
本文介绍了将git子模块中的更改推送到主模块,但不推送到子模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个git项目A,它使用来自Github的子模块B.我不能进入Github项目B,因为它不是我的.我想在B中做一个小的更改,该更改不推送到远程B(因为我无法推送),但是应该推送到A(因此,当有人使用A时,他应该能够看到我的更改).我尝试在B中提交,然后在A中提交,似乎更改已正确提交.当我按A到bitbucket时,它会显示带有新提交的子模块.我试图在其他地方克隆A,但是出现以下错误:

I have a git project A that uses a submodule B from Github. I cannot push to the Github project B because it is not mine. I want to do a small change in B that is not pushed to the remote B (because I can't push) but it should be pushed to A (so when someone uses A, he should be able to see my changes). I tried to commit in B, then commit in A and it seems like the changes are committed correctly. When I push A to bitbucket it shows me the submodule with a new commit. I tried to clone A somewhere else, but I get the following error:

fatal: remote error: upload-pack: not our ref 7b9e40769855bc50f3be629cd8307d76dd8ecf1b
fatal: the remote end hung up unexpectedly
Fetched in submodule path 'src/B', but it did not contain 7b9e40769855bc50f3be629cd8307d76dd8ecf1b. Direct fetching of that commit failed.

我猜找不到新的提交,因为它没有被推送到B的远端.有没有办法解决?我希望保留B作为子模块,以便可以从远程项目中获取更新,但我还需要这些小的更改

I guess the new commit couldn't be found because it was not pushed to the remote of B. Is there any way around this? I'd prefer to keep B as a submodule so I can get updates from the remote project but I also need these small changes

推荐答案

如果要共享它,则必须以某种方式发布它.

If you want to share it, you somehow have to publish it.

一种方法是:

  • 在github上:fork项目 B
  • 发布您想要的分叉
  • 在项目 A 中:更新git模块的远程URL以指向您的fork,并使用提交ID作为您创建的提交.
  • on github: fork project B
  • publish the commit you want on your fork
  • in project A: update the git module remote url to point to your fork, and use the commit id for the commit you created.

稍后,如果您要进行的更改已集成到上游 B 中,则可以切换回项目 B 的原始基本URL.

At a later time, if the changes you want are integrated to upstream B, you can switch back to the original base url for project B.

如果可以的话,另一种选择是,在对 A 的下一次提交中,停止将 B 作为子模块处理,并将其集成为子树.您的回购.

Another option, if you are ok with it, is, in your next commit on A, to stop handling B as a submodule, and integrate it as a subtree of your repo.

这篇关于将git子模块中的更改推送到主模块,但不推送到子模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆