git commit
git
Usage
git commit [-a] -m "<message>"Records what is staged as one commit; -a picks up modified tracked files only, so brand-new files are left out.
Common flags
| Flag | Meaning |
|---|---|
| -m "<msg>" | give the message on the command line |
| -a | stage modified tracked files first; new files are skipped |
| --amend | replace the previous commit instead of adding one |
| --no-edit | keep the old message, used with --amend |
| --fixup=<commit> | mark it to be folded into <commit> by rebase --autosquash |
| -S | sign the commit with GPG |
| --allow-empty | commit with nothing staged |
Examples
git commit -m "fix login redirect"records what is staged
git commit -a -m "typo"stages tracked edits and commits in one step
git commit --amend --no-editfolds the staged change into the last commit, keeping its message
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 commit do?
Records what is staged as one commit; -a picks up modified tracked files only, so brand-new files are left out.
Q. How do I type it?
git commit [-a] -m "<message>" — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
7 are listed here; the full set is in man git. This command sits under git.
Related commands
man page: man git-commit