Push changes in git submodule to main module but not to submodule

為{幸葍}努か 提交于 2021-02-17 05:22:44

问题


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.

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


回答1:


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

One way is :

  • 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.

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.


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.



来源:https://stackoverflow.com/questions/64390808/push-changes-in-git-submodule-to-main-module-but-not-to-submodule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!