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ção | Significado |
|---|---|
| -A | stage every change in the whole tree, deletions included |
| -u | stage changes to tracked files only, no new files |
| -p | walk the diff and choose hunk by hunk |
| -n | dry run: list what would be staged |
| -f | stage a file that .gitignore excludes |
| -N | record the path only, so the file shows up in diffs |
Exemplos
git add -Astages everything, including files you deleted
git add -p src/app.tsstages 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