LinuxCommandLibrary

git-commit

Record changes to the repository

TLDR

Commit staged changes

$ git commit -m "[message]"
copy
Commit all tracked changes
$ git commit -am "[message]"
copy
Amend last commit
$ git commit --amend
copy
Commit with editor
$ git commit
copy
Empty commit
$ git commit --allow-empty -m "[message]"
copy
Commit with signoff
$ git commit -s -m "[message]"
copy
Fixup commit
$ git commit --fixup [commit]
copy
Squash commit
$ git commit --squash [commit]
copy

SYNOPSIS

git commit [options] [--] [files...]

DESCRIPTION

git commit records changes to the repository by creating a new commit object containing the currently staged changes, metadata, and a descriptive message. Each commit represents a snapshot in the repository's history, identified by a unique SHA-1 hash and linked to its parent commit(s).
The standard workflow involves staging changes with git add, then committing those staged changes. The -a flag shortcuts this by automatically staging all modified tracked files before committing. Commit messages can be provided inline with -m or by opening an editor where you can write multi-line messages with detailed explanations.
The --amend option modifies the most recent commit instead of creating a new one, useful for correcting mistakes or adding forgotten changes. This rewrites history, so amended commits should not be pushed to shared branches unless force-pushing is acceptable.
Advanced options support signing commits with GPG (--gpg-sign), adding metadata like co-authors or issue references, and creating specialized commits for rebase workflows. The --fixup and --squash options create commits meant to be combined with earlier commits during interactive rebasing, supporting cleanup of messy development history.
Empty commits (--allow-empty) are occasionally useful for triggering CI/CD pipelines or marking milestones without actual code changes. The --verbose flag shows the full diff in the editor, helping write accurate commit messages by reviewing what's being committed.

PARAMETERS

-m, --message msg

Commit message.
-a, --all
Stage all modified files.
--amend
Amend previous commit.
--no-edit
Use previous message.
-s, --signoff
Add Signed-off-by.
--allow-empty
Allow empty commits.
--fixup commit
Fixup for commit.
--squash commit
Squash into commit.
-v, --verbose
Show diff in editor.
--author author
Override author.

CONFIGURATION

~/.gitconfig [commit]

Commit-related settings including default gpgSign, template, and cleanup behavior.
.git/hooks/commit-msg
Hook script that validates or modifies commit messages before finalizing.
.git/hooks/pre-commit
Hook script that runs checks before allowing a commit to proceed.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community