Início·Comandos de terminal

git diff

git

Uso

git diff [--staged] [<commit>] [-- <path>]

Mostra só as mudanças que ainda não foram preparadas; é por isso que parece vazio logo após git add — use --staged.

Opções comuns

OpçãoSignificado
--stagedcompare the staged snapshot with HEAD (same as --cached)
--statsummary of files and line counts instead of the patch
-wignore whitespace changes
--name-onlylist changed paths only
<a>...<b>changes on b since it forked from a
-- <path>restrict to a path; the -- keeps it from being read as a branch

Exemplos

git diff

shows only what is NOT staged yet

git diff --staged

shows what git commit would record

git diff main...feature

the work feature added since it left main

O confuso é que desfazer tem várias formas: mover para onde um branch aponta não é o mesmo que criar um commit que reverte.

Como ler

  • Os colchetes [ ] marcam uma parte que você pode omitir.
  • As reticências … indicam que você pode listar vários.
  • As opções diferenciam maiúsculas: em alguns comandos -r e -R fazem coisas diferentes.

Perguntas

Q. O que git diff faz?

Mostra só as mudanças que ainda não foram preparadas; é por isso que parece vazio logo após git add — use --staged.

Q. Como se digita?

git diff [--staged] [<commit>] [-- <path>] — os colchetes marcam o que você pode omitir.

Q. Quantas opções vale a pena saber?

Aqui estão 6; a lista completa está em man git. Este comando fica em git.

Comandos relacionados

página man: man git-diff