gitで一部ディレクトリをsubmoduleとして切り出す手順

GitHub 開発ツール

出来たけどこんな回りくどい方法が必要なのかな?
もっと簡単な方法あったら教えて下さい

1.開発中のものとは別にリポジトリをcloneする

~~~
mkdir new_dir
cd new_dir
git clone base-repo .
~~~

2.リポジトリから指定したディレクトリだけ取り出す

~~~
git filter-branch –subdirectory-filter path/to/module HEAD
~~~
※歴史が書き換わって、path/to/moduleのみのコミットログが残ります

3.push先を別にする

~~~
git remote set-url origin new-repo
git push -u origin –all
~~~
※元のままでpush -fとかすると悲惨なことになります

4.元々使っていたディレクトリに戻り、submoduleに登録する

~~~
cd base-repo
rm -rf path/to/module
git rm -r –cached path/to/module
git submodule add new-repo path/to/module
git commit
git push
~~~

コメント

タイトルとURLをコピーしました