2017-06-20 145 views
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文件夾的文件夾位於:

  1. main_repo/unrelated_repo/main_repo_submodule/.git/

但是,如果我把這個子模塊到遠程服務器做執行:

  1. git clone --recursive

子模塊git的文件夾main_repo/unrelated_repo/main_repo_submodule/.git/將位於:

  1. 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的說,子模塊找不到。

回答

1

mv unrelated_repo/main_repo_submodule/.git/ .git/modules 

後,您還需要

mv .git/modules/.git .git/modules/main_repo_submodule 
+1

謝謝!我忘了文件夾,並尋找,我覺得這是更好地只是改變路線發送到正確的文件夾在一次:'MV unrelated_repo/main_repo_submodule/git的/ git的/模塊/ main_repo_submodule'。 – user