git add
git
Usage
git add [-A|-u|-p] <pathspec>...Stages the file as it looks right now; editing it again after add leaves that change out, so you have to add once more.
Common flags
| Flag | Meaning |
|---|---|
| -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 |
Examples
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
The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does git add do?
Stages the file as it looks right now; editing it again after add leaves that change out, so you have to add once more.
Q. How do I type it?
git add [-A|-u|-p] <pathspec>... — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
6 are listed here; the full set is in man git. This command sits under git.
Related commands
man page: man git-add