如何解决Git/Github:管理具有公共和私有子模块的分叉存储库
我有一个包含三个子模块的分叉存储库,它们都是公共的,但我想将其中一个更改为我自己的私有存储库。我克隆存储库,然后执行 git submodule update --init
,git 获取公共存储库,但使用私有存储库,git 会提示一个避免下载的凭据窗口。
.submodule 文件
[submodule "saleor"]
path = saleor
url = https://github.com/mirumee/saleor.git
[submodule "saleor-storefront"] -> I want to replace this one with my private repo
path = saleor-storefront
url = https://github.com/mirumee/saleor-storefront.git
[submodule "saleor-dashboard"]
path = saleor-dashboard
url = https://github.com/mirumee/saleor-dashboard.git
更新 1
VonC 提示answer,出现新错误,无法下载替换的子模块。如何重现此错误:
- 我分叉 saleor-platform repository。
- 我在我的机器上克隆了在步骤 1 中创建的分叉存储库:
D:\git\tests\saleor-platform>git clone https://github.com/<organization>/saleor-platform
- 创建一个新的存储库来替换
saleor-storefront
,saleor-storefront
是saleor-platform
中的一个子模块,该存储库在步骤 1 中分叉。 - 按照 VonC 用户的建议替换子模块 here,需要注意的是,我想将
saleor-storefront
子模块更改为organization
内的私有仓库,这是一个全新的实现,即它只有初始提交:
D:\git\tests\saleor-platform>git submodule set-url -- saleor-storefront https://github.com/<organization>/my-new-brand-implementation
- 从父存储库 (
saleor-platform
) 使用git status
检查新更改,添加新更改git add .
,提交更改git commit -m "Update saleor-storefront submodule"
:
D:\git\tests\saleor-platform>git st
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: .gitmodules
no changes added to commit (use "git add" and/or "git commit -a")
D:\git\tests\saleor-platform>git add .
D:\git\tests\saleor-platform>git commit -m "Update saleor-storefront submodule"
[master 53b60e5] Update saleor-storefront submodule
1 file changed,1 insertion(+),1 deletion(-)
- 推回我的叉子:
D:\git\tests\saleor-platform>git push
Enumerating objects: 5,done.
Counting objects: 100% (5/5),done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3),done.
Writing objects: 100% (3/3),353 bytes | 353.00 KiB/s,done.
Total 3 (delta 2),reused 0 (delta 0),pack-reused 0
remote: Resolving deltas: 100% (2/2),completed with 2 local objects.
To github.com:<organization>/saleor-platform.git
cbc31e4..53b60e5 master -> master
- 最后,我再次克隆了我的存储库:
D:\git\tests\> git clone --recurse-submodules https://github.com/<organization>/saleor-platform saleor-platform2
cloning into 'saleor-platform2'...
remote: Enumerating objects: 9,done.
remote: Counting objects: 100% (9/9),done.
remote: Compressing objects: 100% (9/9),done.
Receiving objects: 67% (138/205)),reused 3 (delta 0),pack-reused 196
Receiving objects: 100% (205/205),68.41 KiB | 463.00 KiB/s,done.
Resolving deltas: 100% (99/99),done.
Submodule 'saleor' (https://github.com/mirumee/saleor.git) registered for path 'saleor'
Submodule 'saleor-dashboard' (https://github.com/mirumee/saleor-dashboard.git) registered for path 'saleor-dashboard'
Submodule 'saleor-storefront' (https://github.com/<organization>/my-new-brand-implementation) registered for path 'saleor-storefront'
cloning into 'D:/git/tests/saleor-platform2/saleor'...
remote: Enumerating objects: 178730,done.
remote: Total 178730 (delta 0),pack-reused 178730
Receiving objects: 100% (178730/178730),100.26 MiB | 2.60 MiB/s,done.
Resolving deltas: 100% (130671/130671),done.
cloning into 'D:/git/tests/saleor-platform2/saleor-dashboard'...
remote: Enumerating objects: 168,done.
remote: Counting objects: 100% (168/168),done.
remote: Compressing objects: 100% (132/132),done.
remote: Total 38062 (delta 69),reused 71 (delta 32),pack-reused 37894
Receiving objects: 100% (38062/38062),24.61 MiB | 1.93 MiB/s,done.
Resolving deltas: 100% (25652/25652),done.
cloning into 'D:/git/tests/saleor-platform2/saleor-storefront'...
remote: Enumerating objects: 113,done.
remote: Counting objects: 100% (113/113),done.
remote: Compressing objects: 100% (98/98),done.
remote: Total 113 (delta 2),reused 113 (delta 2),pack-reused 0
Receiving objects: 100% (113/113),300.56 KiB | 523.00 KiB/s,done.
Resolving deltas: 100% (2/2),done.
Submodule path 'saleor': checked out '3b31391b92b184b591ef4e85ff6a59cd52cdad98'
Submodule path 'saleor-dashboard': checked out '8bcb8b70878078b74133aea0244dc840d75b492f'
fatal: remote error: upload-pack: not our ref 3ba4ffa8a14f90398462b84e5da088baeb84dfc6
fatal: the remote end hung up unexpectedly
Fetched in submodule path 'saleor-storefront',but it did not contain 3ba4ffa8a14f90398462b84e5da088baeb84dfc6. Direct fetching of that commit Failed.
解决方法
如果您的 git config credential.helper
已设置(例如,在 Windows 上设置为 manager-core
),则 Windows 凭据应为 cache your GitHub credentials(GitHub 用户帐户/密码)
先试试:
git ls-remote https://github.com/<me>/saleor-storefront.git
(假设您已分叉 <me>
,将 saleor-storefront
替换为您的 GitHub 用户帐户)
一旦您缓存了您的凭据,并且 git ls-remote
不再要求这些凭据,请再次尝试更改子模块 URL。
确保使用 git submodule set-url
更改 URL,正如我在 your previous question 中建议的那样。
像 the remote end hung up unexpectedly Fetched in submodule path 'saleor-storefront',but it did not contain xxx
这样的错误消息是 explained here。
您需要父存储库(您的 fork)添加并提交新的远程子模块存储库树 SHA1,这应该通过 git submodule set-url
完成,然后推送更新的 fork。
测试:我已经分叉,然后克隆销售平台。
D:\git\tests\saleor-platform>git submodule update --init
Submodule 'saleor' (https://github.com/mirumee/saleor.git) registered for path 'saleor'
Submodule 'saleor-dashboard' (https://github.com/mirumee/saleor-dashboard.git) registered for path 'saleor-dashboard'
Submodule 'saleor-storefront' (https://github.com/mirumee/saleor-storefront.git) registered for path 'saleor-storefront'
Cloning into 'D:/git/tests/saleor-platform/saleor'...
Cloning into 'D:/git/tests/saleor-platform/saleor-dashboard'...
Cloning into 'D:/git/tests/saleor-platform/saleor-storefront'...
Submodule path 'saleor': checked out '3b31391b92b184b591ef4e85ff6a59cd52cdad98'
Submodule path 'saleor-dashboard': checked out '8bcb8b70878078b74133aea0244dc840d75b492f'
Submodule path 'saleor-storefront': checked out '3ba4ffa8a14f90398462b84e5da088baeb84dfc6'
然后我分叉了saleor-storefront
。
我用我自己的分叉子模块替换了那个子模块:
D:\git\tests\saleor-platform>git submodule set-url -- saleor-storefront https://github.com/VonC/saleor-storefront
Synchronizing submodule url for 'saleor-storefront'
更新更改后的 .gitmodules:
D:\git\tests\saleor-platform>git st
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: .gitmodules
no changes added to commit (use "git add" and/or "git commit -a")
D:\git\tests\saleor-platform>git add .
D:\git\tests\saleor-platform>git commit -m "Update saleor-storefront submodule"
[master d9f1f79] Update saleor-storefront submodule
1 file changed,1 insertion(+),1 deletion(-)
推回我的叉子
D:\git\tests\saleor-platform>git push
Enumerating objects: 5,done.
Counting objects: 100% (5/5),done.
Delta compression using up to 4 threads
Compressing objects: 100% (3/3),done.
Writing objects: 100% (3/3),337 bytes | 337.00 KiB/s,done.
Total 3 (delta 2),reused 0 (delta 0),pack-reused 0
remote: Resolving deltas: 100% (2/2),completed with 2 local objects.
To https://github.com/VonC/saleor-platform
cbc31e4..d9f1f79 master -> master
用我的分叉子模块再次克隆主仓库(我的分叉):
D:\git\tests\> git clone --recurse-submodules https://github.com/VonC/saleor-platform saleor-platform2
Cloning into 'saleor-platform2'...
remote: Enumerating objects: 9,done.
remote: Counting objects: 100% (9/9),done.
remote: Compressing objects: 100% (9/9),done.
Receiving objects: 67% (138/205) 205 (delta 3),reused 3 (delta 0),pack-reused 19666% (136/205)
Receiving objects: 100% (205/205),68.40 KiB | 454.00 KiB/s,done.
Resolving deltas: 100% (99/99),done.
Submodule 'saleor' (https://github.com/mirumee/saleor.git) registered for path 'saleor'
Submodule 'saleor-dashboard' (https://github.com/mirumee/saleor-dashboard.git) registered for path 'saleor-dashboard'
Submodule 'saleor-storefront' (https://github.com/VonC/saleor-storefront) registered for path 'saleor-storefront'
Cloning into 'D:/git/tests/saleor-platform2/saleor'...
remote: Enumerating objects: 237,done.
remote: Counting objects: 100% (237/237),done.
remote: Compressing objects: 100% (188/188),done.
remote: Total 178889 (delta 93),reused 78 (delta 49),pack-reused 178652
Receiving objects: 100% (178889/178889),100.57 MiB | 9.63 MiB/s,done.
Resolving deltas: 100% (130714/130714),done.
Cloning into 'D:/git/tests/saleor-platform2/saleor-dashboard'...
remote: Enumerating objects: 12,done.
remote: Counting objects: 100% (12/12),done.
remote: Compressing objects: 100% (12/12),done.
remote: Total 37906 (delta 1),reused 1 (delta 0),pack-reused 37894
Receiving objects: 100% (37906/37906),23.81 MiB | 12.03 MiB/s,done.
Resolving deltas: 100% (25584/25584),done.
Cloning into 'D:/git/tests/saleor-platform2/saleor-storefront'...
remote: Enumerating objects: 46,done.
remote: Counting objects: 100% (46/46),done.
remote: Compressing objects: 100% (37/37),done.
remote: Total 34033 (delta 21),reused 15 (delta 8),pack-reused 33987
Receiving objects: 100% (34033/34033),17.14 MiB | 3.04 MiB/s,done.
Resolving deltas: 100% (23073/23073),done.
Submodule path 'saleor': checked out '3b31391b92b184b591ef4e85ff6a59cd52cdad98'
Submodule path 'saleor-dashboard': checked out '8bcb8b70878078b74133aea0244dc840d75b492f'
Submodule path 'saleor-storefront': checked out '3ba4ffa8a14f90398462b84e5da088baeb84dfc6'
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。