Início·Comandos de terminal

git add

git

Uso

git add [-A|-u|-p] <pathspec>...

Prepara o arquivo como ele está naquele instante; se você editar depois do add, essa mudança fica de fora e precisa de outro add.

Opções comuns

OpçãoSignificado
-Astage every change in the whole tree, deletions included
-ustage changes to tracked files only, no new files
-pwalk the diff and choose hunk by hunk
-ndry run: list what would be staged
-fstage a file that .gitignore excludes
-Nrecord the path only, so the file shows up in diffs

Exemplos

git add -A

stages everything, including files you deleted

git add -p src/app.ts

stages part of one file and leaves the rest

git add .

stages everything under the current directory

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 add faz?

Prepara o arquivo como ele está naquele instante; se você editar depois do add, essa mudança fica de fora e precisa de outro add.

Q. Como se digita?

git add [-A|-u|-p] <pathspec>... — 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-add