Olá! No momento, esta página ainda está sendo desenvolvida ou traduzida. Para obter as informações mais recentes, acesse a documentação em inglês.
Versão do artigo: Enterprise Server 2.15

Esta versão do GitHub Enterprise será descontinuada em Esta versão do GitHub Enterprise foi descontinuada em 2019-10-16. No patch releases will be made, even for critical security issues. For better performance, improved security, and new features, upgrade to the latest version of GitHub Enterprise. For help with the upgrade, contact GitHub Enterprise support.

Sobre merges de subárvore do Git

Se precisar gerenciar vários projetos em um único repositório, você poderá usar um merge de subárvore para manipular todas as referências.

Normalmente, um merge de subárvore é usado para conter um repositório dentro de outro repositório. O "sub-repositório" é armazenado em uma pasta do repositório principal.

A melhor maneira de explicar merges de subárvore é mostrar com exemplo. O que faremos:

Configurar o repositório vazio para um merge de subárvore

  1. Abra Terminal (Terminal)Terminal (Terminal)Git Basho terminal.

  2. Crie um novo diretório e navegue até ele.

    $ mkdir test
    $ cd test
  3. Inicialize um novo repositório Git.

    $ git init
    > Initialized empty Git repository in /Users/octocat/tmp/test/.git/
  4. Crie e faça commit de um novo arquivo.

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

Adding a new repository as a subtree

  1. Adicione uma nova URL remota apontando para o projeto separado em que estávamos interessados.

    $ git remote add -f spoon-knife git@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 git://github.com/octocat/Spoon-Knife
    >  * [new branch]      master     -> Spoon-Knife/master
  2. Merge the Spoon-Knife project into the local Git project. Isso não muda qualquer um de seus arquivos localmente, mas prepara o Git para a próxima etapa.

    If you're using Git 2.9 or above:

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

    If you're using Git 2.8 or below:

    $ git merge -s ours --no-commit spoon-knife/master
    > Automatic merge went well; stopped before committing as requested
  3. Create a new directory called spoon-knife, and copy the Git history of the Spoon-Knife project into it.

    $ git read-tree --prefix=spoon-knife/ -u spoon-knife/master
  4. Faça commit das alterações para mantê-las seguras.

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

Although we've only added one subproject, any number of subprojects can be incorporated into a Git repository.

Tip: If you create a fresh clone of the repository in the future, the remotes you've added will not be created for you. You will have to add them again using the git remote add command.

Synchronizing with updates and changes

When a subproject is added, it is not automatically kept in sync with the upstream changes. You will need to update the subproject with the following command:

$ git pull -s subtree remotename branchname

Para o exemplo acima, o comando seria:

$ git pull -s subtree spoon-knife master

Leia mais

Pergunte a uma pessoa

Não consegue encontrar o que procura?

Entrar em contato