Skip to content

Instantly share code, notes, and snippets.

@Scemist
Last active October 4, 2022 20:59
Show Gist options
  • Save Scemist/96d02c72a05c144a16023060b43bad0b to your computer and use it in GitHub Desktop.
Save Scemist/96d02c72a05c144a16023060b43bad0b to your computer and use it in GitHub Desktop.
Main Git Commands

Comandos Git

Súmario

Básicos

  • q (Sair)
  • git
  • git status
  • git commit -m "Titulo" -m "Descrição"
  • git commit --amend -m "Titulo" -m "Descrição" (Faz um commit substituindo o último)
  • git init (Inicia um repositório)
  • git init --bare (Inicia um repositório do tipo bare)
  • git config user.name "Lucas Scemist"
  • git config user.email "scemist.lucas@gmail.com"
  • git remote set-url origin https://[token]@github.com/[perfil]/[repo]
  • git add [arquivo]

Reverter Problema

  • git revert [0000000] (Cria um novo commit sem as alterações do último commit)
  • git restore [arquivo]
  • git restore --staged [arquivo]
  • git restore checkout [arquivo]
  • git reset HEAD~1 (Remove o commit)
  • git reset --hard HEAD^ (Deleta o último commit)
  • git checkout -- [arquivo] (Volta para como estava antes, arquivos untracked)
  • git checkout HEAD -- [arquivo] (Volta para como estava antes, arquivos staged)

Manipulando Repositórios

  • git clone /c:/desenvolvimento/cursogit .
  • git remote add origin https://github.com/Scemist/GeekUniversity1.git
  • git remote -v (Mostra se tem e qual a origem configurada)
  • git push (Envia as modificações do repo. local para o repo. remoto)
  • git push -u origin master
  • git push origin v1.0
  • git fetch (Atualiza as alterações do repo. remoto para o repo. local)
  • git merge
  • git rebase
  • git pull (Fetch + rebase: atualiza o workspace a partir do repo. local)

Log de Commits

  • git help log
  • git log
  • git log -2
  • git log --oneline
  • git log --before="2021-04-15"
  • git log --after="2021-02-12" -2
  • git log --since="2 days ago"
  • git log --after="1 week ago"
  • git log --before="1 month ago"
  • git log --author="Scemist"

Navegação no Workspace

  • git stash (Salva os adicionados em um backup)
  • git stash pop (Restaura os itens do backup)
  • git checkout master (Após um checkout)
  • git checkout [branch] (Muda para a branch)
  • git checkout -b funcionalidadeC
  • git checkout [hash] (Muda para o commit)
  • git checkout [versão] (Muda para a tag)

Comparar Códigos

  • git diff --staged
  • git diff [hash]
  • git diff [hash]..[hash]

Manipulando Arquivos com Git

  • git mv [arquivo] [nome novo] (Renomear)
  • git rm [arquivo] (Remove)

Manipulando Branches

  • git branch
  • git switch [nova-ferramenta] (Alterna entre branchs (use -c para mudar criando uma))
  • git branch [funcionalidadeA]
  • git branch -d [funcionalidadeA]
  • git merge [funcionalidadeB] (A partir da branch master)
  • git branch -d [funcialidadeB] (Para deletar a branch)
  • git merge master (A partir da [funcionalidade]) (Para manter a [funcionalidade] atualizada)

Versões, Tag e Releases

  • git checkout [2.3.0] (Muda para uma outra tag)
  • git tag (Mostra as tags)
  • git describe --tags (Mostra a tag atual, a última)
  • git tag [v1.0] (Cria uma nova tag)

Parar de rastrear arquivos modificados

  • git update-index --assume-unchanged [arquivo]
  • git update-index --no-assume-unchanged [arquivo]

Remember

^ and ~

  • HEAD^1 Referencia o último 1 commit da branch atual (poderia ser HEAD^2, últimos 2 commits), HEAD^ é atalho para 1

~[n] é um atalho para vários ^ HEAD~3 é equivalente à HEAD^^^

HEAD^[n] NÃO É

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment