2017-01-21 11 views
1

私はサブモジュールを持つプロジェクトを持っており、サブモジュールがクローンされているかのように、サブモジュールのディレクトリ.gitを再構築できるようにしたいと考えています。より詳細にはサブモジュールの.gitディレクトリを再構築する方法はありますか?

、私はgitのプロジェクトsuperprojectにサブモジュールsubprojectを持っている、と私はすでにやっていると言う:

git clone git://url.of.superproject 
cd superproject 
git submodule update --init 

subprojectが指し、独自の.gitディレクトリが、.gitファイルを持っていませんディレクトリ../.git/modules/subprojectsubprojectの実際の.gitディレクトリが必要です。私が使用しているツール(Pythonのpip)は、subprojectディレクトリを任意の場所にコピーしてgitコマンドを実行する作業を行うためです。

subproject/.gitディレクトリを複製したかのように再構築する方法はありますか?私はディレクトリの他の部分への相対リンクを含んでいるので、.git/modules/subprojectディレクトリをコピーするだけではなりません。 - 自分の質問に答えるために

+0

' core.worktree'設定?あなたのサブプロジェクトがそれ以上ネストされていなければ、単に 'cdサブプロジェクト; git = $(git rev-parse --git-dir); rm .git && mv "$ git" .git && git config --unset core.worktree'を実行します。 – jthill

+0

提案していただきありがとうございます。私は、相対リンクはかなり共通でなければならないと思う - 本当の例であなたのレシピを試してみるhttps://github.com/MacPython/cython-wheels、サブプロジェクト 'Cython'は私に壊れたサブモジュール' Could not chdir to .. '../ .. /../ Cython'。 –

+0

Hunh。 'git --work-tree =。 config --unset core.worktree'を修正しました。 – jthill

答えて

1

git clone subproject.gitディレクトリ構築します:今すぐsubproject-copy/.git

git clone --recursive subproject subproject-copy 

をフルgitのディレクトリです。

function fill_submodule { 
    # Restores .git directory to submodule, if necessary 
    local repo_dir="$1" 
    [ -z "$repo_dir" ] && echo "repo_dir not defined" && exit 1 
    local git_loc="$repo_dir/.git" 
    # For ordinary submodule, .git is a file. 
    [ -d "$git_loc" ] && return 
    # Need to recreate .git directory for submodule 
    local origin_url=$(cd "$repo_dir" && git config --get remote.origin.url) 
    local repo_copy="$repo_dir-$RANDOM" 
    git clone --recursive "$repo_dir" "$repo_copy" 
    rm -rf "$repo_dir" 
    mv "$repo_copy" "$repo_dir" 
    (cd "$repo_dir" && git remote set-url origin $origin_url) 
} 

使用して::ここで

は、より一般的な方法でこれを行うには、bashの機能(リモート正しく originを再構築する、など)だほか、いくつかの相対的なリンクがあります

fill_submodule subproject 
関連する問題