2017-06-20 20 views
0

ローカルでこのスクリプトのようにgitのサブモジュールを作成します。gitサブモジュールフォルダ `.git`を親リポジトリの` .git/modules/`フォルダに送る方法は?

サブモジュール .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 

:私はこれをプッシュする場合、

  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/

、その場所に親リポジトリ上のgitのフォルダにsynlinkになります。どのようにサブモジュールを置くかは、この親フォルダ.git/modules/フォルダに作成するだけです。再帰的にクローンを作成する必要はありませんか?

新しいサブモジュールが追加されるたびにすべてを再帰的に再クローンする必要なしに、サブモジュールフォルダを親モジュールフォルダに保持して、作業領域をきれいに保つ必要があるからです。

更新

私がやってみました:

# 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/modules/main_repo_submodule'を一度に送信するだけで良いと思う。 – user

関連する問題