pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://docs.github.com/ja/get-started/using-git/about-git-subtree-merges

atest" data-next-head=""/>
Skip to main content

Gitのサブツリーのマージについて

複数のプロジェクトを単一のリポジトリで管理する必要がある場合、 "サブツリー マージ" を使ってすべての参照を扱うことができます。

サブツリーのマージについて

通常、サブツリーのマージはリポジトリ内にリポジトリを格納するために使われます。 「サブリポジトリ」はメインのリポジトリのフォルダー内に格納されます。

サブツリーマージは、例で説明するのが最も分かりやすいでしょう。 以下のように進めます:

  • プロジェクトを表す test という空のリポジトリを作成します。
  • 別のリポジトリを Spoon-Knife というサブツリーとして、そこにマージします。
  • test プロジェクトでは、そのサブプロジェクトを同じリポジトリの一部であるかのように使います。
  • Spoon-Knife から test プロジェクトに更新プログラムを取り込みます。

サブツリーマージのための空のリポジトリのセットアップ

複数のOSを扱うターミナルを開く

  1. 新しいディレクトリを作成し、そこに移動します。

    mkdir test
    cd test
    
  2. 新しい Git リポジトリを初期化します。

    $ git init
    > Initialized empty Git repository in /Users/octocat/tmp/test/.git/
    
  3. 新しいファイルを作成してコミットします。

    $ touch .gitignore
    $ git add .gitignore
    $ git commit -m "initial commit"
    > [main (root-commit) 3146c2a] initial commit
    >  0 files changed, 0 insertions(+), 0 deletions(-)
    >  create mode 100644 .gitignore
    

新しいリポジトリをサブツリーとして追加

  1. 関心のある別個のプロジェクトを指す新しいリモート URL を追加します。

    $ git remote add -f spoon-knife https://github.com/octocat/Spoon-Knife.git
    > Updating spoon-knife
    > warning: no common commits
    > remote: Counting objects: 1732, done.
    > remote: Compressing objects: 100% (750/750), done.
    > remote: Total 1732 (delta 1086), reused 1558 (delta 967)
    > Receiving objects: 100% (1732/1732), 528.19 KiB | 621 KiB/s, done.
    > Resolving deltas: 100% (1086/1086), done.
    > From https://github.com/octocat/Spoon-Knife
    >  * [new branch]      main     -> Spoon-Knife/main
    
  2.        `Spoon-Knife` プロジェクトをローカルの Git プロジェクトにマージします。 こうしてもローカルではファイルはまったく変更されませんが、Git は次のステップに備えることになります。
    

    Git 2.9 以降を使用している場合:

    $ git merge -s ours --no-commit --allow-unrelated-histories spoon-knife/main
    > Automatic merge went well; stopped before committing as requested
    

    Git 2.8 以前を使用している場合:

    $ git merge -s ours --no-commit spoon-knife/main
    > Automatic merge went well; stopped before committing as requested
    
  3.        **spoon-knife** というディレクトリを新たに作成し、`Spoon-Knife` プロジェクトの Git 履歴をそこへコピーします。
    
    $ git read-tree --prefix=spoon-knife/ -u spoon-knife/main
    > fatal: refusing to merge unrelated histories
    
  4. 変更をコミットして安全にします。

    $ git commit -m "Subtree merged in spoon-knife"
    > [main fe0ca25] Subtree merged in spoon-knife
    

ここでは 1 つのサブプロジェクトを追加しただけですが、Git リポジトリには任意の数のサブプロジェクトを取り込むことができます。

ヒント

将来このリポジトリのクローンを新しく作成した場合、追加したリモートは作成されません。 git remote add コマンドを使用して、もう一度追加する必要があります。

更新と変更に同期する

サブプロジェクトが追加された場合、そのサブプロジェクトは上流の変更と自動的には同期されません。 以下のコマンドで、サブプロジェクトを更新する必要があります。

git pull -s subtree REMOTE-NAME BRANCH-NAME

上の例では、以下のようになるでしょう:

git pull -s subtree spoon-knife main

参考資料

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy