简体   繁体   English

git子模块的不同推/拉网址

[英]different push/pull urls for git submodule

I'm using the git superproject pattern in a large project which is deployed by a Teamcity build agent which does not have a repository account, however the repository is set up to allow anonymous cloning. 我在一个大型项目中使用git superproject模式 ,该项目由没有存储库帐户的Teamcity构建代理部署,但是存储库设置为允许匿名克隆。 For this reason I have set up the submodules with their http:// url rather than their git url. 出于这个原因,我已经使用他们的http:// url而不是他们的git url设置了子模块。 The issue with this is that the repository rejects http pushes: 这个问题是存储库拒绝http推送:

Total 0 (delta 0), reused 0 (delta 0)
error: RPC failed; result=22, HTTP code = 401
fatal: The remote end hung up unexpectedly
fatal: The remote end hung up unexpectedly

So every time I update the submodules when switching branches, I have to do a git remote add-url --push to add the git:// url. 所以每当我在切换分支时更新子模块,我都要做一个git remote add-url --push来添加git:// url。

Is there any way to set up the submodules in the superproject such that they already use the http:// url for pulling and the git:// url for pushing? 有没有办法在超级项目中设置子模块,以便他们已经使用http:// url进行提取,使用git:// url进行推送?

The LibreOffice project also uses submodules and includes: LibreOffice项目还使用子模块 ,包括:

By default you submodules repository is in a state called 'detached HEAD' that means that the commit checked-out -- which is the one that the super-project (core) need -- is not associated with a local branch name. 默认情况下,子模块存储库处于称为“分离的HEAD”的状态,这意味着提交签出 - 超级项目(核心)所需的 - 不与本地分支名称相关联。

Don't forget to add a correct pushurl for the submodule you are working on or you will not be able to commit. 不要忘记为正在处理的子模块添加正确的pushurl,否则您将无法提交。

$ editor .git/modules/submodule/config

And in the section [remote "origin"] add: [remote "origin"]部分中添加:

pushurl = ssh://logerrit/submodule

(similar to soulseekah 's comment ) (in your case, use a git:// address) (类似于soulseekah评论 )(在你的情况下,使用git://地址)

You can also do it through (within a submodule) 您也可以通过(在子模块内)完成

git config remote.origin.pushurl git://...

If you don't, as illulstrated in this project , you would get a: 如果不这样做,因为在illulstrated 这个项目 ,你会得到一个:

fatal: The remote end hung up unexpectedly

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM