git commands
git commit
Record what is staged as a new commit on the current branch, with a message that says why.
git commit -m <message>Angle brackets are yours to fill in. Windows, Linux, macOS.
Examples for git commit
Stage and commit every changed file in one step
git commit -am "<message>"-a stages each tracked file that changed, then commits. Files git does not track yet are left out: add those with git add first.
gittoolcommitsubcommand-amstage tracked changes, then message"<message>"argumentChange the last commit message
git commit --amend -m "<message>"Replaces the most recent commit with one that has the same changes and the new message. If anything is staged, it goes into the commit too. Do this only before you push, or be ready to force-push.
Rewrites the last commit. A pushed commit then needs --force-with-lease.
gittoolcommitsubcommand--amendreplace the last commit-m "<message>"flag with valueAdd a forgotten file to the last commit
git commit --amend --no-editStage the file with git add first, then run this. The last commit is replaced by one that includes the file, and the message stays the same.
Rewrites the last commit. A pushed commit then needs --force-with-lease.
gittoolcommitsubcommand--amendflag--no-editkeep the messageMake an empty commit to trigger CI
git commit --allow-empty -m "<message>"Records a commit with no changes. Pushing it starts the pipeline again without touching a file.
gittoolcommitsubcommand--allow-emptyno changes needed-m "<message>"flag with value
Flags
- --message -m <message>
- Give the message on the command line instead of in an editor. Repeat -m to add a paragraph.
- --all -a
- Stage every modified tracked file before committing. New, untracked files are not included.
- --amend
- Replace the last commit with a new one that has the staged changes and, optionally, a new message.Rewrites a commit. If the old one was already pushed, the next push needs --force-with-lease, and anyone who pulled it must recover.
- --no-edit
- With --amend, keep the existing message instead of opening the editor.
- --allow-empty
- Make a commit that changes no files, for example to start a CI run.
- --no-verify -n
- Skip the pre-commit and commit-msg hooks.The hooks are often the lint, test or secret scan. Skipping them commits what they would have stopped.