Top > GIT > リポジトリの統合


リポジトリの統合

rebase 編

repo.old というリポジトリに、repo.new リポジトリを取込み、統合する

  • コマンド
    $ cd repo.old
    $ git fetch ../repo.new refs/heads/master:fefs/heads/new-branch
    $ git checkout new-branch
    $ git rebase master
    (コンフリクトが発生したら都度対応、git add, git rebase --continue)
    $ git checkout master
    $ git merge new-branch
    $ git branch -d new-branch
  • 解説
    • 古いリポジトリ(repo.old)に対して、new-branch というブランチ名で、 新しいリポジトリ(repo.new)を取込む (fetch)
    • new-branch の始点を master ブランチの先頭に持ってくる (rebase)
    • master ブランチに new-branch ブランチの内容をマージする (merge)


remote add 編

2つのリポジトリ統合して1つのリポジトリにする

  • コマンド
    $ cd repo1
    $ git remote add repo2 ../repo2
    $ git fetch repo2
    $ git merge repo2/master
  • 解説
    • repo1 に対して、repo2 のリモートリポジトリを追加する (remote add)
    • repo2 の変更点全てを取込む (fetch)
    • repo2 リモートの master ブランチをマージする (merge)


サブディレクトリ

あるリポジトリのサブディレクトリに別のリポジトリを取込む

  • コマンド
    $ cd repo1
    
    ## そもそも subdir が存在しないとき
    $ mkdir subdir
    $ touch subdir/.gitkeep
    $ git add -A subdir
    $ git commit -m 'create subdir'
    
    ## 取込む
    $ git remote add repo2 ../repo2
    $ git fetch repo2
    $ git merge -X subtree=subdir repo2/master
  • 解説
    • subdir が存在しない場合は、事前にディレクトリを作成し、git 登録できるようにダミーのファイル(.gitkeep)を作成して (add/push)
    • 上記同様 (remote add)
    • merge のオプション -X subtree=subdir を使用して、サブディレクトリに (merge)



リロード   凍結解除 コピー 名前変更   ホーム 一覧 検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS
Last-modified: Mon, 03 Jun 2019 14:37:49 UTC (2201d)