我正在使用.gitmodules檔案為我的主倉庫指定一個 git 子模塊:
[submodule "SUBMODULE"]
path = ...
url = ...
然后在命令列中:git clone MAINREPO --recursive.
是否可以在克隆命令中指定要檢出的子模塊的提交?
uj5u.com熱心網友回復:
對你的問題的簡短回答是:沒辦法。資訊寫在提交的超級專案中,存盤有關子模塊更改的資訊。每次跑
git clone --recursive superproject-url
或者
git checkout --recursive some-old-commit
Git 在 HEAD 中查找子模塊的提交或正在檢出的舊提交并檢出存盤的子模塊提交。
如果你想更改存盤在 HEAD 中的提交:轉到本地克隆的子模塊,檢查提交,回傳到超級專案,添加并提交子模塊中的更改,推送:
cd subdir
git checkout branch-tag-or-ID
cd .. # back to the superproject
git add subdir
git commit -m "Change in subdir" subdir
如果要更改為的子模塊中的提交是 HEAD,則可以在超級專案中執行
git submodule update --remote subdir
git commit -m "Change in subdir" subdir
除了命令列選項,您還可以執行(使用 shell 腳本或 git 別名)git clone --recursive && cd subdir && git checkout commit-ID。這是唯一的方法。就像是
# .gitconfig
[alias]
clone-sub = "!f() { git clone --recursive \"$1\" && cd \"$2\" && git checkout \"$3\"; }; f"
用法:git clone-sub superproject-url submodule-path commit-ID
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/536319.html
標籤:混帐git子模块
