GIT

De Wiki DAINF
(Diferença entre revisões)
Linha 9: Linha 9:
  
 
   <nowiki>[emerson@localhost TESTES]$ git --help </nowiki>
 
   <nowiki>[emerson@localhost TESTES]$ git --help </nowiki>
   <nowiki>usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate|--no-pager] [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE] [--help] COMMAND [ARGS] </nowiki>
+
   <nowiki>usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate|--no-pager] [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE] [--help] COMMAND [ARGS] </nowiki><br />
 
+
   The most commonly used git commands are:<br />
   The most commonly used git commands are:
+
 
+
 
       add Add file contents to the index  
 
       add Add file contents to the index  
 
       bisect Find by binary search the change that introduced a bug  
 
       bisect Find by binary search the change that introduced a bug  
Linha 33: Linha 31:
 
       show Show various types of objects  
 
       show Show various types of objects  
 
       status Show the working tree status  
 
       status Show the working tree status  
       tag Create, list, delete or verify a tag object signed with GPG  
+
       tag Create, list, delete or verify a tag object signed with GPG <br />
 
+
 
   See 'git help COMMAND' for more information on a specific command.  
 
   See 'git help COMMAND' for more information on a specific command.  
  
Linha 46: Linha 43:
  
 
'''Obs:''' para que o usuário ‘surfx’ realizasse o push no branch git@github.com:adolfont/TESTES.git do colaborador ‘adolfont’, é necessário que o usuário ‘adolfont’ adicione o colaborador ‘surfx’ no branch <nowiki>[mailto:git@github.com git@github.com]:adolfont/TESTES.git</nowiki>, conforme '''Figura 1'''.
 
'''Obs:''' para que o usuário ‘surfx’ realizasse o push no branch git@github.com:adolfont/TESTES.git do colaborador ‘adolfont’, é necessário que o usuário ‘adolfont’ adicione o colaborador ‘surfx’ no branch <nowiki>[mailto:git@github.com git@github.com]:adolfont/TESTES.git</nowiki>, conforme '''Figura 1'''.
<br />
+
<br /><br />
 
[[Imagem:GITcolaboradores.PNG]]<br />
 
[[Imagem:GITcolaboradores.PNG]]<br />
 
'''Figura 1 – Colaboradores Git'''
 
'''Figura 1 – Colaboradores Git'''
Linha 53: Linha 50:
 
Adicionado uma pasta para teste:
 
Adicionado uma pasta para teste:
  
<nowiki>[emerson@localhost ~]$ cd Desktop/ </nowiki>
+
  <nowiki>[emerson@localhost ~]$ cd Desktop/ </nowiki>
 
+
  <nowiki>[emerson@localhost Desktop]$ mkdir testegithub </nowiki>
<nowiki>[emerson@localhost Desktop]$ mkdir testegithub </nowiki>
+
  <nowiki>[emerson@localhost Desktop]$ cd testegithub/ </nowiki>
 
+
<nowiki>[emerson@localhost Desktop]$ cd testegithub/ </nowiki>
+
 
+
  
 
“Clonando” dos dados do Git do colaborador ‘adolfont’:
 
“Clonando” dos dados do Git do colaborador ‘adolfont’:
  
<nowiki>[emerson@localhost testegithub]$ git clone git://github.com/adolfont/TESTES.git </nowiki>
+
  <nowiki>[emerson@localhost testegithub]$ git clone git://github.com/adolfont/TESTES.git </nowiki>
 
+
  Initialized empty Git repository in /home/emerson/Desktop/testegithub/TESTES/.git/  
Initialized empty Git repository in /home/emerson/Desktop/testegithub/TESTES/.git/  
+
  remote: Counting objects: 18, done.  
 
+
  remote: Compressing objects: 100% (10/10), done.  
remote: Counting objects: 18, done.  
+
  remote: Total 18 (delta 3), reused 0 (delta 0)  
 
+
  Receiving objects: 100% (18/18), done.  
remote: Compressing objects: 100% (10/10), done.  
+
  Resolving deltas: 100% (3/3), done.  
 
+
  <nowiki>[emerson@localhost testegithub]$ cd TESTES/ </nowiki>
remote: Total 18 (delta 3), reused 0 (delta 0)  
+
 
+
Receiving objects: 100% (18/18), done.  
+
 
+
Resolving deltas: 100% (3/3), done.  
+
 
+
<nowiki>[emerson@localhost testegithub]$ cd TESTES/ </nowiki>
+
 
+
  
 
Recupera o ramo atual:
 
Recupera o ramo atual:
 
+
  <nowiki>[emerson@localhost TESTES]$ git branch </nowiki>
<nowiki>[emerson@localhost TESTES]$ git branch </nowiki>
+
  <nowiki>* master </nowiki>
 
+
<nowiki>* master </nowiki>
+
 
+
  
 
Lista os arquivos do diretório:
 
Lista os arquivos do diretório:
 
+
  <nowiki>[emerson@localhost TESTES]$ ls </nowiki>
<nowiki>[emerson@localhost TESTES]$ ls </nowiki>
+
  README  
 
+
  <nowiki>[emerson@localhost TESTES]$ cat README </nowiki>
README  
+
  This file is here only for testing git.  
 
+
  AQUI ESTÁ A ALTERAÇÃO CONFLITANTE....  
<nowiki>[emerson@localhost TESTES]$ cat README </nowiki>
+
  Fazendo alteração conflitante.  
 
+
  Gedit é um comando do Linux que permite editar um arquivo:
This file is here only for testing git.  
+
  <nowiki>[emerson@localhost TESTES]$ gedit README </nowiki>
 
+
AQUI ESTÁ A ALTERAÇÃO CONFLITANTE....  
+
 
+
Fazendo alteração conflitante.  
+
 
+
 
+
Gedit é um comando do Linux que permite editar um arquivo:
+
 
+
<nowiki>[emerson@localhost TESTES]$ gedit README </nowiki>
+
 
+
  
 
Este comando do git adidciona novos arquivos:
 
Este comando do git adidciona novos arquivos:
 
+
  <nowiki>[emerson@localhost TESTES]$ git add . </nowiki>
<nowiki>[emerson@localhost TESTES]$ git add . </nowiki>
+
 
+
  
 
Commit dos dados na máquina local (-m ‘’ representa um comentário):
 
Commit dos dados na máquina local (-m ‘’ representa um comentário):
 +
  <nowiki>[emerson@localhost TESTES]$ git commit -a -m 'Testando alteração' </nowiki>
 +
  <nowiki>[master 2f9be95] Testando alteração </nowiki>
 +
  2 files changed, 8 insertions(+), 0 deletions(-)
 +
  create mode 100644 README~
  
<nowiki>[emerson@localhost TESTES]$ git commit -a -m 'Testando alteração' </nowiki>
+
Enviar os arquivos para o git do colaborador (<nowiki>[mailto:git@github.com git@github.com]:adolfont/TESTES.git</nowiki> é o link do servidor GitHub do colaborador):
 
+
  emerson@localhost TESTES]$ git push <nowiki>git@github.com:adolfont/TESTES.git</nowiki> master  
<nowiki>[master 2f9be95] Testando alteração </nowiki>
+
  Counting objects: 5, done.  
 
+
  Compressing objects: 100% (3/3), done.  
2 files changed, 8 insertions(+), 0 deletions(-)
+
  Writing objects: 100% (3/3), 353 bytes, done.  
 
+
  Total 3 (delta 1), reused 0 (delta 0)  
create mode 100644 README~
+
  To git@github.com:adolfont/TESTES.git  
 
+
  4253dde..2f9be95 master -> master  
 
+
Enviar os arquivos para o git do colaborador ([mailto:git@github.com git@github.com]:adolfont/TESTES.git é o link do servidor GitHub do colaborador):
+
 
+
emerson@localhost TESTES]$ git push git@github.com:adolfont/TESTES.git master  
+
 
+
Counting objects: 5, done.  
+
 
+
Compressing objects: 100% (3/3), done.  
+
 
+
Writing objects: 100% (3/3), 353 bytes, done.  
+
 
+
Total 3 (delta 1), reused 0 (delta 0)  
+
 
+
To git@github.com:adolfont/TESTES.git  
+
 
+
4253dde..2f9be95 master -> master  
+
 
+
  
 
'''Comandos comuns do GIT'''
 
'''Comandos comuns do GIT'''
Linha 143: Linha 101:
  
 
Para trocar de ramo:
 
Para trocar de ramo:
 
+
  <nowiki>[emerson@localhost TESTES]$ git checkout -b experimental </nowiki>
<nowiki>[emerson@localhost TESTES]$ git checkout -b experimental </nowiki>
+
  Switched to a new branch 'experimental'  
 
+
Switched to a new branch 'experimental'  
+
 
+
  
 
Listar os ramos existentes:
 
Listar os ramos existentes:
 
+
  <nowiki>[emerson@localhost TESTES]$ git branch</nowiki>
<nowiki>[emerson@localhost TESTES]$ git branch </nowiki>
+
  <nowiki>* experimental </nowiki>
 
+
  master  
<nowiki>* experimental </nowiki>
+
 
+
master  
+
 
+
  
 
Para excluir um ramo:
 
Para excluir um ramo:
 
+
  <nowiki>[emerson@localhost TESTES]$ git branch -d experimental </nowiki>
<nowiki>[emerson@localhost TESTES]$ git branch -d experimental </nowiki>
+
  Deleted branch experimental (was 2f9be95).  
 
+
Deleted branch experimental (was 2f9be95).  
+
 
+
  
 
Para criar um ramo:
 
Para criar um ramo:
 
+
  <nowiki>[emerson@localhost TESTES]$ git branch master </nowiki>
<nowiki>[emerson@localhost TESTES]$ git branch master </nowiki>
+
 
+
  
 
Checkout em um ramo:
 
Checkout em um ramo:
 
+
  <nowiki>[emerson@localhost TESTES]$ git checkout master </nowiki>
<nowiki>[emerson@localhost TESTES]$ git checkout master </nowiki>
+
 
+
  
 
Recuperar o log do GIT:
 
Recuperar o log do GIT:
 
+
  <nowiki>[emerson@localhost TESTES]$ git log </nowiki>
<nowiki>[emerson@localhost TESTES]$ git log </nowiki>
+
 
+
  
 
Listar os ramos existentes:
 
Listar os ramos existentes:
 
+
  <nowiki>[emerson@localhost TESTES]$ git branch -r </nowiki>
<nowiki>[emerson@localhost TESTES]$ git branch -r </nowiki>
+
  origin/HEAD  
 
+
  origin/experimental  
origin/HEAD  
+
  origin/master  
 
+
origin/experimental  
+
 
+
origin/master  
+
 
+
  
 
Recuperar o ramo no qual você esta:
 
Recuperar o ramo no qual você esta:
 
+
  <nowiki>[emerson@localhost TESTES]$ git branch </nowiki>
<nowiki>[emerson@localhost TESTES]$ git branch </nowiki>
+
  <nowiki>* master </nowiki>
 
+
<nowiki>* master </nowiki>
+
 
+
  
 
Checkout:
 
Checkout:
 
+
  <nowiki>[emerson@localhost TESTES]$ git checkout master </nowiki>
<nowiki>[emerson@localhost TESTES]$ git checkout master </nowiki>
+
 
+
  
 
Editar um arquivo:
 
Editar um arquivo:
 
+
  <nowiki>[emerson@localhost TESTES]$ cat README </nowiki>
<nowiki>[emerson@localhost TESTES]$ cat README </nowiki>
+
 
+
  
 
Editar um arquivo (linux):
 
Editar um arquivo (linux):
 
+
  <nowiki>[emerson@localhost TESTES]$ gedit README </nowiki>
<nowiki>[emerson@localhost TESTES]$ gedit README </nowiki>
+
 
+
  
 
Commit local (-m ‘comentário’):
 
Commit local (-m ‘comentário’):
 
+
  <nowiki>[emerson@localhost TESTES]$ git commit -a -m 'ex de comentario - modificacao' </nowiki>
<nowiki>[emerson@localhost TESTES]$ git commit -a -m 'ex de comentario - modificacao' </nowiki>
+
 
+
  
 
Add todos os novos arquivos:
 
Add todos os novos arquivos:
 
+
  <nowiki>[emerson@localhost TESTE_EMERSON]$ git add . </nowiki>
<nowiki>[emerson@localhost TESTE_EMERSON]$ git add . </nowiki>
+
 
+
  
 
Inicializar GIT:
 
Inicializar GIT:
 +
  <nowiki>[emerson@localhost TESTES2]$ </nowiki>git init
 +
  Initialized empty Git repository in /home/emerson/Desktop/testegithub/TESTES2/.git/
  
<nowiki>[emerson@localhost TESTES2]$ </nowiki>git init
+
Adicionar no servidor (<nowiki>[mailto:git@github.com git@github.com]:surfx/TESTES2.git</nowiki> é o link no servidor do GitHub):
 
+
  <nowiki>[emerson@localhost TESTES2]$ git remote add origin </nowiki><nowiki>[mailto:git@github.com git@github.com]:surfx/TESTES2.git</nowiki>
Initialized empty Git repository in /home/emerson/Desktop/testegithub/TESTES2/.git/
+
 
+
 
+
Adicionar no servidor ([mailto:git@github.com git@github.com]:surfx/TESTES2.git é o link no servidor do GitHub):
+
 
+
<nowiki>[emerson@localhost TESTES2]$ git remote add origin </nowiki>[mailto:git@github.com git@github.com]:surfx/TESTES2.git  
+
 
+
  
 
Enviar os arquivos para o servidor:
 
Enviar os arquivos para o servidor:
 
+
  <nowiki>[emerson@localhost TESTES2]$ git push origin master </nowiki>
<nowiki>[emerson@localhost TESTES2]$ git push origin master </nowiki>
+
 
+
  
 
Outra forma de se enviar os arquivos para o servidor ([mailto:git@github.com git@github.com]:surfx/TESTES.git é o link no servidor do GitHub):
 
Outra forma de se enviar os arquivos para o servidor ([mailto:git@github.com git@github.com]:surfx/TESTES.git é o link no servidor do GitHub):
 
+
  <nowiki>[emerson@localhost TESTES]$ git push git@github.com:surfx/TESTES.git master</nowiki>
<nowiki>[emerson@localhost TESTES]$ git push git@github.com:surfx/TESTES.git master</nowiki>
+
 
+
  
 
Enviar os arquivos para o git do colaborador ([mailto:git@github.com git@github.com]:adolfont/TESTES.git é o link do servidor GitHub do colaborador):
 
Enviar os arquivos para o git do colaborador ([mailto:git@github.com git@github.com]:adolfont/TESTES.git é o link do servidor GitHub do colaborador):
 
+
  emerson@localhost TESTES]$ git push git@github.com:adolfont/TESTES.git master  
emerson@localhost TESTES]$ git push git@github.com:adolfont/TESTES.git master  
+
  Counting objects: 5, done.  
 
+
  Compressing objects: 100% (3/3), done.  
Counting objects: 5, done.  
+
  Writing objects: 100% (3/3), 353 bytes, done.  
 
+
  Total 3 (delta 1), reused 0 (delta 0)  
Compressing objects: 100% (3/3), done.  
+
  To <nowiki>git@github.com:adolfont/TESTES.git</nowiki>
 
+
  4253dde..2f9be95 master -> master
Writing objects: 100% (3/3), 353 bytes, done.  
+
 
+
Total 3 (delta 1), reused 0 (delta 0)  
+
 
+
To git@github.com:adolfont/TESTES.git  
+
 
+
4253dde..2f9be95 master -> master
+

Edição de 09h12min de 20 de outubro de 2009

GIT


Como usar o Git junto com outros colaboradores para controle de versão.


Ajuda do GIT:


  [emerson@localhost TESTES]$ git --help 
  usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate|--no-pager] [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE] [--help] COMMAND [ARGS] 
The most commonly used git commands are:
add Add file contents to the index bisect Find by binary search the change that introduced a bug branch List, create, or delete branches checkout Checkout a branch or paths to the working tree clone Clone a repository into a new directory commit Record changes to the repository diff Show changes between commits, commit and working tree, etc fetch Download objects and refs from another repository grep Print lines matching a pattern init Create an empty git repository or reinitialize an existing one log Show commit logs merge Join two or more development histories together mv Move or rename a file, a directory, or a symlink pull Fetch from and merge with another repository or a local branch push Update remote refs along with associated objects rebase Forward-port local commits to the updated upstream head reset Reset current HEAD to the specified state rm Remove files from the working tree and from the index show Show various types of objects status Show the working tree status tag Create, list, delete or verify a tag object signed with GPG
See 'git help COMMAND' for more information on a specific command.


Considerações para este exemplo

  Os exemplos são feitos em linha de comando do Linux.
  Site do GitHub: https://github.com/
  Link do git usuário ‘surfx’: [mailto:git@github.com git@github.com]:surfx
  Link do git colaborador ‘adolfont’: [mailto:git@github.com git@github.com]:adolfont

Obs: para que o usuário ‘surfx’ realizasse o push no branch git@github.com:adolfont/TESTES.git do colaborador ‘adolfont’, é necessário que o usuário ‘adolfont’ adicione o colaborador ‘surfx’ no branch [mailto:git@github.com git@github.com]:adolfont/TESTES.git, conforme Figura 1.

GITcolaboradores.PNG
Figura 1 – Colaboradores Git


Adicionado uma pasta para teste:

  [emerson@localhost ~]$ cd Desktop/ 
  [emerson@localhost Desktop]$ mkdir testegithub 
  [emerson@localhost Desktop]$ cd testegithub/ 

“Clonando” dos dados do Git do colaborador ‘adolfont’:

  [emerson@localhost testegithub]$ git clone git://github.com/adolfont/TESTES.git 
  Initialized empty Git repository in /home/emerson/Desktop/testegithub/TESTES/.git/ 
  remote: Counting objects: 18, done. 
  remote: Compressing objects: 100% (10/10), done. 
  remote: Total 18 (delta 3), reused 0 (delta 0) 
  Receiving objects: 100% (18/18), done. 
  Resolving deltas: 100% (3/3), done. 
  [emerson@localhost testegithub]$ cd TESTES/ 

Recupera o ramo atual:

  [emerson@localhost TESTES]$ git branch 
  * master 

Lista os arquivos do diretório:

  [emerson@localhost TESTES]$ ls 
  README 
  [emerson@localhost TESTES]$ cat README 
  This file is here only for testing git. 
  AQUI ESTÁ A ALTERAÇÃO CONFLITANTE.... 
  Fazendo alteração conflitante. 
  Gedit é um comando do Linux que permite editar um arquivo:
  [emerson@localhost TESTES]$ gedit README 

Este comando do git adidciona novos arquivos:

  [emerson@localhost TESTES]$ git add . 

Commit dos dados na máquina local (-m ‘’ representa um comentário):

  [emerson@localhost TESTES]$ git commit -a -m 'Testando alteração' 
  [master 2f9be95] Testando alteração 
  2 files changed, 8 insertions(+), 0 deletions(-) 
  create mode 100644 README~ 

Enviar os arquivos para o git do colaborador ([mailto:git@github.com git@github.com]:adolfont/TESTES.git é o link do servidor GitHub do colaborador):

  emerson@localhost TESTES]$ git push git@github.com:adolfont/TESTES.git master 
  Counting objects: 5, done. 
  Compressing objects: 100% (3/3), done. 
  Writing objects: 100% (3/3), 353 bytes, done. 
  Total 3 (delta 1), reused 0 (delta 0) 
  To git@github.com:adolfont/TESTES.git 
  4253dde..2f9be95 master -> master 

Comandos comuns do GIT


Para trocar de ramo:

  [emerson@localhost TESTES]$ git checkout -b experimental 
  Switched to a new branch 'experimental' 

Listar os ramos existentes:

  [emerson@localhost TESTES]$ git branch
  * experimental 
  master 

Para excluir um ramo:

  [emerson@localhost TESTES]$ git branch -d experimental 
  Deleted branch experimental (was 2f9be95). 

Para criar um ramo:

  [emerson@localhost TESTES]$ git branch master 

Checkout em um ramo:

  [emerson@localhost TESTES]$ git checkout master 

Recuperar o log do GIT:

  [emerson@localhost TESTES]$ git log 

Listar os ramos existentes:

  [emerson@localhost TESTES]$ git branch -r 
  origin/HEAD 
  origin/experimental 
  origin/master 

Recuperar o ramo no qual você esta:

  [emerson@localhost TESTES]$ git branch 
  * master 

Checkout:

  [emerson@localhost TESTES]$ git checkout master 

Editar um arquivo:

  [emerson@localhost TESTES]$ cat README 

Editar um arquivo (linux):

  [emerson@localhost TESTES]$ gedit README 

Commit local (-m ‘comentário’):

  [emerson@localhost TESTES]$ git commit -a -m 'ex de comentario - modificacao' 

Add todos os novos arquivos:

  [emerson@localhost TESTE_EMERSON]$ git add . 

Inicializar GIT:

  [emerson@localhost TESTES2]$ git init 
  Initialized empty Git repository in /home/emerson/Desktop/testegithub/TESTES2/.git/ 

Adicionar no servidor ([mailto:git@github.com git@github.com]:surfx/TESTES2.git é o link no servidor do GitHub):

  [emerson@localhost TESTES2]$ git remote add origin [mailto:git@github.com git@github.com]:surfx/TESTES2.git 

Enviar os arquivos para o servidor:

  [emerson@localhost TESTES2]$ git push origin master 

Outra forma de se enviar os arquivos para o servidor (git@github.com:surfx/TESTES.git é o link no servidor do GitHub):

  [emerson@localhost TESTES]$ git push git@github.com:surfx/TESTES.git master

Enviar os arquivos para o git do colaborador (git@github.com:adolfont/TESTES.git é o link do servidor GitHub do colaborador):

  emerson@localhost TESTES]$ git push git@github.com:adolfont/TESTES.git master 
  Counting objects: 5, done. 
  Compressing objects: 100% (3/3), done. 
  Writing objects: 100% (3/3), 353 bytes, done. 
  Total 3 (delta 1), reused 0 (delta 0) 
  To git@github.com:adolfont/TESTES.git 
  4253dde..2f9be95 master -> master
Ferramentas pessoais