GIT

De Wiki DAINF
(Diferença entre revisões)
(Nova página: 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_PAT...)
 
Linha 1: Linha 1:
 +
'''GIT'''
  
GIT
 
  
 
Como usar o Git junto com outros colaboradores para controle de versão.
 
Como usar o Git junto com outros colaboradores para controle de versão.
 +
  
 
Ajuda do GIT:
 
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]  
+
<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>
 +
 
  
 
The most commonly used git commands are:  
 
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  
+
add Add file contents to the index  
  branch     List, create, or delete branches  
+
 
  checkout   Checkout a branch or paths to the working tree  
+
bisect Find by binary search the change that introduced a bug  
  clone     Clone a repository into a new directory  
+
 
  commit     Record changes to the repository  
+
branch List, create, or delete branches  
  diff       Show changes between commits, commit and working tree, etc  
+
 
  fetch     Download objects and refs from another repository  
+
checkout Checkout a branch or paths to the working tree  
  grep       Print lines matching a pattern  
+
 
  init       Create an empty git repository or reinitialize an existing one  
+
clone Clone a repository into a new directory  
  log       Show commit logs  
+
 
  merge     Join two or more development histories together  
+
commit Record changes to the repository  
  mv         Move or rename a file, a directory, or a symlink  
+
 
  pull       Fetch from and merge with another repository or a local branch  
+
diff Show changes between commits, commit and working tree, etc  
  push       Update remote refs along with associated objects  
+
 
  rebase     Forward-port local commits to the updated upstream head  
+
fetch Download objects and refs from another repository  
  reset     Reset current HEAD to the specified state  
+
 
  rm         Remove files from the working tree and from the index  
+
grep Print lines matching a pattern  
  show       Show various types of objects  
+
 
  status     Show the working tree status  
+
init Create an empty git repository or reinitialize an existing one  
  tag       Create, list, delete or verify a tag object signed with GPG  
+
 
 +
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.  
 
See 'git help COMMAND' for more information on a specific command.  
  
  
Considerações para este exemplo
+
'''Considerações para este exemplo'''
 +
 
  
 
Os exemplos são feitos em linha de comando do Linux.
 
Os exemplos são feitos em linha de comando do Linux.
Site do GitHub: https://github.com/
 
Link do git usuário ‘surfx’:  git@github.com:surfx
 
Link do git colaborador ‘adolfont’:  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 git@github.com:adolfont/TESTES.git, conforme Figura 1.
+
Site do GitHub: [https://github.com/ https://github.com/]
  
 +
Link do git usuário ‘surfx’: [mailto:git@github.com git@github.com]:surfx
  
Figura 1 – Colaboradores Git
+
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'''.
 +
 
 +
 
 +
[[Image:]]'''Figura 1 – Colaboradores Git'''
  
  
 
Adicionado uma pasta para teste:
 
Adicionado uma pasta para teste:
[emerson@localhost ~]$ cd Desktop/  
+
 
[emerson@localhost Desktop]$ mkdir testegithub  
+
<nowiki>[emerson@localhost ~]$ cd Desktop/ </nowiki>
[emerson@localhost Desktop]$ cd testegithub/  
+
 
 +
<nowiki>[emerson@localhost Desktop]$ mkdir 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’:
[emerson@localhost testegithub]$ git clone git://github.com/adolfont/TESTES.git
+
 
 +
<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: Counting objects: 18, done.  
 +
 
remote: Compressing objects: 100% (10/10), done.  
 
remote: Compressing objects: 100% (10/10), done.  
 +
 
remote: Total 18 (delta 3), reused 0 (delta 0)  
 
remote: Total 18 (delta 3), reused 0 (delta 0)  
 +
 
Receiving objects: 100% (18/18), done.  
 
Receiving objects: 100% (18/18), done.  
 +
 
Resolving deltas: 100% (3/3), done.  
 
Resolving deltas: 100% (3/3), done.  
[emerson@localhost testegithub]$ cd TESTES/  
+
 
 +
<nowiki>[emerson@localhost testegithub]$ cd TESTES/ </nowiki>
 +
 
  
 
Recupera o ramo atual:
 
Recupera o ramo atual:
[emerson@localhost TESTES]$ git branch  
+
 
* master  
+
<nowiki>[emerson@localhost TESTES]$ git branch </nowiki>
 +
 
 +
<nowiki>* master </nowiki>
 +
 
  
 
Lista os arquivos do diretório:
 
Lista os arquivos do diretório:
[emerson@localhost TESTES]$ ls  
+
 
 +
<nowiki>[emerson@localhost TESTES]$ ls </nowiki>
 +
 
 
README  
 
README  
[emerson@localhost TESTES]$ cat README  
+
 
 +
<nowiki>[emerson@localhost TESTES]$ cat README </nowiki>
 +
 
 
This file is here only for testing git.  
 
This file is here only for testing git.  
  AQUI ESTÁ A ALTERAÇÃO CONFLITANTE....  
+
 
 +
AQUI ESTÁ A ALTERAÇÃO CONFLITANTE....  
 +
 
 
Fazendo alteração conflitante.  
 
Fazendo alteração conflitante.  
 +
  
 
Gedit é um comando do Linux que permite editar um arquivo:
 
Gedit é um comando do Linux que permite editar um arquivo:
[emerson@localhost TESTES]$ gedit README  
+
 
 +
<nowiki>[emerson@localhost TESTES]$ gedit README </nowiki>
 +
 
  
 
Este comando do git adidciona novos arquivos:
 
Este comando do git adidciona novos arquivos:
[emerson@localhost TESTES]$ git add .  
+
 
 +
<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):
[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 (git@github.com:adolfont/TESTES.git é o link do servidor GitHub do colaborador):
+
<nowiki>[emerson@localhost TESTES]$ git commit -a -m 'Testando alteração' </nowiki>
emerson@localhost TESTES]$ git push git@github.com:adolfont/TESTES.git master  
+
 
 +
<nowiki>[master 2f9be95] Testando alteração </nowiki>
 +
 
 +
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.  
 
Counting objects: 5, done.  
 +
 
Compressing objects: 100% (3/3), done.  
 
Compressing objects: 100% (3/3), done.  
 +
 
Writing objects: 100% (3/3), 353 bytes, done.  
 
Writing objects: 100% (3/3), 353 bytes, done.  
 +
 
Total 3 (delta 1), reused 0 (delta 0)  
 
Total 3 (delta 1), reused 0 (delta 0)  
 +
 
To git@github.com:adolfont/TESTES.git  
 
To git@github.com:adolfont/TESTES.git  
  4253dde..2f9be95  master -> master
 
  
 +
4253dde..2f9be95 master -> master
 +
 +
 +
'''Comandos comuns do GIT'''
  
Comandos comuns do GIT
 
  
 
Para trocar de ramo:
 
Para trocar de ramo:
[emerson@localhost TESTES]$ git checkout -b experimental  
+
 
 +
<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:
[emerson@localhost TESTES]$ git branch  
+
 
* experimental  
+
<nowiki>[emerson@localhost TESTES]$ git branch </nowiki>
  master  
+
 
 +
<nowiki>* experimental </nowiki>
 +
 
 +
master  
 +
 
  
 
Para excluir um ramo:
 
Para excluir um ramo:
[emerson@localhost TESTES]$ git branch -d experimental  
+
 
 +
<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:
[emerson@localhost TESTES]$ git branch master  
+
 
 +
<nowiki>[emerson@localhost TESTES]$ git branch master </nowiki>
 +
 
  
 
Checkout em um ramo:
 
Checkout em um ramo:
[emerson@localhost TESTES]$ git checkout master  
+
 
 +
<nowiki>[emerson@localhost TESTES]$ git checkout master </nowiki>
 +
 
  
 
Recuperar o log do GIT:
 
Recuperar o log do GIT:
[emerson@localhost TESTES]$ git log  
+
 
 +
<nowiki>[emerson@localhost TESTES]$ git log </nowiki>
 +
 
  
 
Listar os ramos existentes:
 
Listar os ramos existentes:
[emerson@localhost TESTES]$ git branch -r  
+
 
  origin/HEAD  
+
<nowiki>[emerson@localhost TESTES]$ git branch -r </nowiki>
  origin/experimental  
+
 
  origin/master  
+
origin/HEAD  
 +
 
 +
origin/experimental  
 +
 
 +
origin/master  
 +
 
  
 
Recuperar o ramo no qual você esta:
 
Recuperar o ramo no qual você esta:
[emerson@localhost TESTES]$ git branch  
+
 
* master  
+
<nowiki>[emerson@localhost TESTES]$ git branch </nowiki>
 +
 
 +
<nowiki>* master </nowiki>
 +
 
  
 
Checkout:
 
Checkout:
[emerson@localhost TESTES]$ git checkout master  
+
 
 +
<nowiki>[emerson@localhost TESTES]$ git checkout master </nowiki>
 +
 
  
 
Editar um arquivo:
 
Editar um arquivo:
[emerson@localhost TESTES]$ cat README  
+
 
 +
<nowiki>[emerson@localhost TESTES]$ cat README </nowiki>
 +
 
  
 
Editar um arquivo (linux):
 
Editar um arquivo (linux):
[emerson@localhost TESTES]$ gedit README  
+
 
 +
<nowiki>[emerson@localhost TESTES]$ gedit README </nowiki>
 +
 
  
 
Commit local (-m ‘comentário’):
 
Commit local (-m ‘comentário’):
[emerson@localhost TESTES]$ git commit -a -m 'ex de comentario - modificacao'  
+
 
 +
<nowiki>[emerson@localhost TESTES]$ git commit -a -m 'ex de comentario - modificacao' </nowiki>
 +
 
  
 
Add todos os novos arquivos:
 
Add todos os novos arquivos:
[emerson@localhost TESTE_EMERSON]$ git add .  
+
 
 +
<nowiki>[emerson@localhost TESTE_EMERSON]$ git add . </nowiki>
 +
 
  
 
Inicializar GIT:
 
Inicializar GIT:
[emerson@localhost TESTES2]$   git init  
+
 
 +
<nowiki>[emerson@localhost TESTES2]$ </nowiki>git init  
 +
 
 
Initialized empty Git repository in /home/emerson/Desktop/testegithub/TESTES2/.git/  
 
Initialized empty Git repository in /home/emerson/Desktop/testegithub/TESTES2/.git/  
  
Adicionar no servidor (git@github.com:surfx/TESTES2.git é o link no servidor do GitHub):
+
 
[emerson@localhost TESTES2]$ git remote add origin git@github.com:surfx/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:
[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):
+
<nowiki>[emerson@localhost TESTES2]$ git push origin master </nowiki>
[emerson@localhost TESTES]$ git push git@github.com:surfx/TESTES.git master
+
 
 +
 
 +
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>
 +
 
 +
 
 +
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  
  
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.  
 
Counting objects: 5, done.  
 +
 
Compressing objects: 100% (3/3), done.  
 
Compressing objects: 100% (3/3), done.  
 +
 
Writing objects: 100% (3/3), 353 bytes, done.  
 
Writing objects: 100% (3/3), 353 bytes, done.  
 +
 
Total 3 (delta 1), reused 0 (delta 0)  
 
Total 3 (delta 1), reused 0 (delta 0)  
 +
 
To git@github.com:adolfont/TESTES.git  
 
To git@github.com:adolfont/TESTES.git  
  4253dde..2f9be95 master -> master
+
 
 +
4253dde..2f9be95 master -> master

Edição de 11h07min de 19 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’: git@github.com:surfx

Link do git colaborador ‘adolfont’: 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 git@github.com:adolfont/TESTES.git, conforme Figura 1.


[[Image:]]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 (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 (git@github.com:surfx/TESTES2.git é o link no servidor do GitHub):

[emerson@localhost TESTES2]$ git remote add origin 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