Git、複数のリポジトリを一つにまとめる
やりたいこと
ReopA,RepoBがある。ReboB/masterをRepoA/repob-branchにコピーしたい
方法
追記: git fetch location refs/heads/branch-from:refs/heads/branch-to でいける、とJunio様に教えていただきました(ひー)。コメント参照。
各リポジトリの位置を/repo_a,/repo_bとする
1. RepoBのオブジェクトを全部RepoAにコピー。
$ cp -rf /repo_b/.git/objects /repo_a/.git/
2. RepoB/masterのオブジェクトIDを調べる
[/repo_b]$ cat .git/refs/heads/master 37e7c1e20928bc...
3. 2で調べたコミットオブジェクトをチェックアウトする
[/repo_a]$ git checkout -b repob-branch 37e7c1e20928bc...
4. お好みでgit gcとかする
感想
- gitのオブジェクトモデルは超絶わかりやすくてかわいい
- しかし.gitの中身いじらずとも、もっとシンプルな方法がありそうな予感。