Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[do-not-merge] #109 Tradução do capítulo 7.11 para pt-br #110

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 48 additions & 48 deletions book/07-git-tools/sections/submodules.asc
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
[[r_git_submodules]]
=== Submodules
=== Submódulos

It often happens that while working on one project, you need to use another project from within it.
Perhaps it’s a library that a third party developed or that you’re developing separately and using in multiple parent projects.
A common issue arises in these scenarios: you want to be able to treat the two projects as separate yet still be able to use one from within the other.
Muitas vezes acontece que, ao trabalhar em um projeto, você precisa usar outro projeto de dentro dele.
Talvez seja uma biblioteca desenvolvida por terceiros, ou que você esteja desenvolvendo separadamente e sendo usada por vários projetos pai.
Um problema comum surge nesses cenários: você deseja poder tratar os dois projetos como separados e ainda poder usar um dentro do outro.

Here’s an example.
Suppose you’re developing a website and creating Atom feeds.
Instead of writing your own Atom-generating code, you decide to use a library.
You’re likely to have to either include this code from a shared library like a CPAN install or Ruby gem, or copy the source code into your own project tree.
The issue with including the library is that it’s difficult to customize the library in any way and often more difficult to deploy it, because you need to make sure every client has that library available.
The issue with copying the code into your own project is that any custom changes you make are difficult to merge when upstream changes become available.
Aqui está um exemplo
Suponha que você esteja desenvolvendo um site e criando Atom feeds.
Em vez de escrever seu próprio código gerador de Atom, você decide usar uma biblioteca.
Provavelmente você terá que incluir esse código de uma biblioteca compartilhada, como um CPAN ou uma Ruby gem, ou copiar o código fonte em sua própria árvore de projeto.
O problema de incluir a biblioteca é a dificuldade de curtomiza-la de qualquer forma e, muitas vezes, você precisa garantir que todos os clientes tenham essa biblioteca disponível.
O problema de copiar o código em seu próprio projeto é que quaisquer alterações feitas na origem são difíceis de mesclar quando ficam disponíveis.

Git addresses this issue using submodules.
Submodules allow you to keep a Git repository as a subdirectory of another Git repository.
This lets you clone another repository into your project and keep your commits separate.
O Git resolve esse problema usando submódulos.
Os submódulos permitem que você mantenha um repositório Git como um subdiretório de outro repositório Git.
Isso permite clonar outro repositório dentro do seu projeto e manter seus commits separados.

[[r_starting_submodules]]
==== Starting with Submodules
==== Começando com Submódulos

We'll walk through developing a simple project that has been split up into a main project and a few sub-projects.
Nós vamos percorrer o desenvolvimento de um projeto simples que foi dividido em um projeto principal e alguns subprojetos.

Let's start by adding an existing Git repository as a submodule of the repository that we're working on.
To add a new submodule you use the `git submodule add` command with the absolute or relative URL of the project you would like to start tracking.
In this example, we'll add a library called ``DbConnector''.
Vamos começar adicionando um repositório Git existente como um submódulo do repositório em que estamos trabalhando.
Para adicionar um novo submódulo se usa o comand `git submodule add` com a URL absoluta ou relativa do projeto que você quer começar a monitorar.
Nesse exemplo, nós vamos adicionar uma biblioteca chamada ``DbConnector''.

[source,console]
----
Expand All @@ -36,10 +36,10 @@ Unpacking objects: 100% (11/11), done.
Checking connectivity... done.
----

By default, submodules will add the subproject into a directory named the same as the repository, in this case ``DbConnector''.
You can add a different path at the end of the command if you want it to go elsewhere.
Por padrão, submódulos adicionarão o subprojeto dentro de um diretório com o mesmo nome do repositório, nessa caso ``DbConnector''.
Você pode adicionar um caminho diferente no final do comando se quiser que vá para outro lugar.

If you run `git status` at this point, you'll notice a few things.
Se você executar `git status` nesse ponto, você notará algumas coisas.

[source,console]
----
Expand All @@ -54,8 +54,8 @@ Changes to be committed:
new file: DbConnector
----

First you should notice the new `.gitmodules` file.
This is a configuration file that stores the mapping between the project’s URL and the local subdirectory you’ve pulled it into:
Primeiro você deve notar o novo arquivo `.gitmodules`.
Esse é um arquivo de configuração que armateza o mapeamento entre a URL do projeto e o subdiretório local para o qual você o puxou:

[source,ini]
----
Expand All @@ -64,21 +64,21 @@ This is a configuration file that stores the mapping between the project’s URL
url = https://github.com/chaconinc/DbConnector
----

If you have multiple submodules, you’ll have multiple entries in this file.
It’s important to note that this file is version-controlled with your other files, like your `.gitignore` file.
It’s pushed and pulled with the rest of your project.
This is how other people who clone this project know where to get the submodule projects from.
Se você tem multiplos submódulos, terá multiplas entradas neste arquivo.
É importante notar que esse arquivo é controlado por versão com seus outros arquivos, como seu arquivo `.gitignore`.
Ele é empurrado (push) e puxado (pull) com o resto do seu projeto.
É assim que outras pessoas que clonam este projeto sabem de onde obter os projetos do submódulo.

[NOTE]
=====
Since the URL in the .gitmodules file is what other people will first try to clone/fetch from, make sure to use a URL that they can access if possible.
For example, if you use a different URL to push to than others would to pull from, use the one that others have access to.
You can overwrite this value locally with `git config submodule.DbConnector.url PRIVATE_URL` for your own use.
When applicable, a relative URL can be helpful.
Como a URL no arquivo .gitmodules é o que outras pessoas tentarão clonar/buscar primeiro, tenha certeza de usar uma URL que possa ser acessada se possível.
Por exemplo, se você usar uma URL diferente para enviar por push do que outros usariam para pegar por pull, use a que outros possuem acesso.
Você pode sobrescrever o valor localmente com `git config submodule.DbConnector.url PRIVATE_URL` para seu próprio uso.
Quando aplicável, a URL relativa por ser útil.
=====

The other listing in the `git status` output is the project folder entry.
If you run `git diff` on that, you see something interesting:
A outra listagem na saída de `git status` é a entrada da pasta do projeto.
Se você executar `git diff`, verá algo interessante:

[source,console]
----
Expand All @@ -92,10 +92,10 @@ index 0000000..c3f01dc
+Subproject commit c3f01dc8862123d317dd46284b05b6892c7b29bc
----

Although `DbConnector` is a subdirectory in your working directory, Git sees it as a submodule and doesn’t track its contents when you’re not in that directory.
Instead, Git sees it as a particular commit from that repository.
Embora `DbConnector` seja um subdiretório no seu diretório de trabalho, Git entende como um submódulo e não rastreia seu conteúdo quando cocê não está nesse diretório.
Em vez disso, o Git o entende como um commit específico desse repositório.

If you want a little nicer diff output, you can pass the `--submodule` option to `git diff`.
Se você gostaria de uma saída do diff um pouco melhor, você pode passar a opção `--submodule` no `git diff`.

[source,console]
----
Expand All @@ -112,7 +112,7 @@ index 0000000..71fc376
Submodule DbConnector 0000000...c3f01dc (new submodule)
----

When you commit, you see something like this:
Quando você faz um commit, você vê algo assim:

[source,console]
----
Expand All @@ -123,21 +123,21 @@ $ git commit -am 'added DbConnector module'
create mode 160000 DbConnector
----

Notice the `160000` mode for the `DbConnector` entry.
That is a special mode in Git that basically means you’re recording a commit as a directory entry rather than a subdirectory or a file.
Observe o modo `160000` para a entrada `DbConnector`.
Isso é um modo especial no Git que, basicamente, significa que você está gravando um commit como uma entrada de diretório ao invés de um subdiretório ou arquivo.

Lastly, push these changes:
Finalmente, faça um push dessas alterações:

[source,console]
----
$ git push origin master
----

[[r_cloning_submodules]]
==== Cloning a Project with Submodules
==== Clonando um projeto com Submódulos

Here we’ll clone a project with a submodule in it.
When you clone such a project, by default you get the directories that contain submodules, but none of the files within them yet:
Aqui vamos clonar um projeto com um submódulo nele.
Quando você clona tal projeto, por padrão, você obtém os diretórios que contêm submódulos, mas nenhum dos arquivos dentro deles ainda:

[source,console]
----
Expand Down Expand Up @@ -165,8 +165,8 @@ $ ls
$
----

The `DbConnector` directory is there, but empty.
You must run two commands: `git submodule init` to initialize your local configuration file, and `git submodule update` to fetch all the data from that project and check out the appropriate commit listed in your superproject:
O diretório `DbConnector` está lá, mas vazio.
Você deve executar dois comandos: `git submodule init` para inicializar o arquivo de configuração local, e `git submodule update` para buscar todos os dados desse projeto e verificar o commit apropriado listado em seu superprojeto:

[source,console]
----
Expand All @@ -182,10 +182,10 @@ Checking connectivity... done.
Submodule path 'DbConnector': checked out 'c3f01dc8862123d317dd46284b05b6892c7b29bc'
----

Now your `DbConnector` subdirectory is at the exact state it was in when you committed earlier.
Agora seu subdiretório `DbConnector` está no estado exato em que estava quando você fez o commit anteriormente.

There is another way to do this which is a little simpler, however.
If you pass `--recursive` to the `git clone` command, it will automatically initialize and update each submodule in the repository.
Existe outra forma de fazer isso um pouco mais simples.
Se você passar `--recursive` no comando `git clone`, isso, automaticamente irá inicializar e atualizar cada submódulo no diretório.

[source,console]
----
Expand Down
2 changes: 1 addition & 1 deletion status.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"sections/searching.asc": 0,
"sections/signing.asc": 0,
"sections/stashing-cleaning.asc": 0,
"sections/submodules.asc": 0,
"sections/submodules.asc": 33,
"sections/subtree-merges.asc": 0
},
"08-customizing-git": {
Expand Down