0
当你在本地创建的git子模块作为此脚本:如何一个git子模块的文件夹`.git`发送到父版本库git的`/模块/`文件夹?
# Create the directory structure
mkdir main_repo
mkdir main_repo/unrelated_repo
mkdir main_repo/unrelated_repo/main_repo_submodule
cd main_repo
# Setup the unrelated_repo
cd unrelated_repo
printf "# UnRelated Repository\n\n" > README.md
git init
git add -f README.md
git commit -m "Added the unrelated repository first commit."
git remote add origin https://github.com/user/unrelated_repo
# Setup the main_repo_submodule
cd main_repo_submodule
printf "# Main Repository Submodule\n\nThis is a submodule from the \`main_repo\`, and not from the \`unrelated_repo\`\n" > README.md
git init
git add -f README.md
git commit -m "Added the main repository submodule first commit."
git remote add origin https://github.com/user/main_repo_submodule
# Setup the main_repo
cd ../..
printf "# Main Repo\n\nThis is the main repository which contains submodules\n" > README.md
printf "\nThis is a main_repo_file on the unrelated repository\n\n" > unrelated_repo/main_repo_file.txt
printf "\n*\n**\n\n" > unrelated_repo/.gitignore
git init
git add -f README.md unrelated_repo/main_repo_file.txt unrelated_repo/.gitignore
git submodule add -f -- https://github.com/user/main_repo_submodule "unrelated_repo/main_repo_submodule"
git commit -m "Added the first main repository first commit."
git remote add origin https://github.com/user/main_repo
子模块.git
文件夹的文件夹位于:
main_repo/unrelated_repo/main_repo_submodule/.git/
但是,如果我把这个子模块到远程服务器做执行:
git clone --recursive
子模块git的文件夹main_repo/unrelated_repo/main_repo_submodule/.git/
将位于:
main_repo/.git/modules/main_repo_submodule/
并在其位置将是一个synlink对父版本库的git的文件夹中。因此,如何把一个子模块只是创建这个父文件夹.git/modules/
文件夹,wihtout递归克隆呢?
,因为我想保持主模块文件夹我的文件夹的子模块,保持工作区干净整洁,而不必每次添加一个新的子模块时递归重新克隆一切有必要。
更新
我试着这样做:
# Move the submodule to the parent repository
mkdir -p .git/modules
# shopt -s dotglob
mv unrelated_repo/main_repo_submodule/.git/ .git/modules
printf "gitdir: ../../.git/modules/main_repo_submodule\n" > unrelated_repo/main_repo_submodule/.git
但是git的说,子模块找不到。
谢谢!我忘了文件夹,并寻找,我觉得这是更好地只是改变路线发送到正确的文件夹在一次:'MV unrelated_repo/main_repo_submodule/git的/ git的/模块/ main_repo_submodule'。 – user