LinuxCommandLibrary

commit

Save changes to the repository

SYNOPSIS

git commit [options] [--] [<pathspec>...]

PARAMETERS

-a, --all
    Stage all modified/deleted tracked files automatically

-c <commit>, --copy <commit>
    Reuse commit message from specified commit

--amend
    Amend the tip of current branch; reuse/replace previous message

-b <name>, --branch <name>
    Use specified branch name for commit

--cleanup=<mode>
    Specify how to clean commit message: verbatim, whitespace, strip, default

-e, --edit
    Prompt to edit commit message (default)

-F <file>, --file=<file>
    Read commit message from given file

--fixup=<commit>
    Reuse message for autosquash fixup of specified commit

-m <msg>, --message=<msg>
    Commit message to use

--no-edit
    Use provided message without opening editor

--no-verify
    Bypass pre-commit and commit-msg hooks

--no-post-rewrite
    Do not run post-rewrite hook

-n, --no-status
    Do not show status (deprecated)

--note=<note>
    Store note with commit

--only
    Commit only specified paths/trees

--patch, -p
    Use interactive patch selection

--reuse-message=<commit>, -C <commit>
    Reuse commit message from specified commit

-i, --interactive
    Interactive mode for selecting hunks

--trailer=<token>[=<value>]
    Add specified trailer to message

-s, --signoff
    Add Signed-off-by trailer

--no-gpg-sign
    Do not GPG sign commit

--gpg-sign[=<key-id>]
    GPG sign with specified key

--no-allow-empty
    Prevent empty commits

--allow-empty
    Allow empty commits

--allow-empty-message
    Allow empty commit message

--squash=<commit>
    Reuse message for squash of specified commit

--reset-author
    Reset author to committer identity

--author=<author>
    Override author name/email

--date=<date>
    Override commit date

-u[=<mode>], --untracked-files[=<mode>]
    Show untracked files: no|normal|all

-v, --verbose
    Show diffstat and summary

--dry-run
    Dry run without creating commit

-q, --quiet
    Suppress commit summary

DESCRIPTION

The git commit command captures a snapshot of the project's currently staged changes, creating a permanent record in the Git history. It is a fundamental operation in Git version control, allowing developers to save incremental changes with descriptive messages.

Before committing, files must be staged using git add. The commit includes the author, date, and a user-provided message summarizing the changes. Commits form the backbone of branches and enable features like reverting, merging, and collaboration.

Options allow amending previous commits, signing commits cryptographically, or bypassing hooks. By default, it opens an editor for the commit message. Use -m for inline messages. Commits are local until pushed with git push.

This command ensures atomic, tamper-evident history, supporting distributed workflows. Always write clear messages following conventional formats like imperative mood and 50-character limits for readability.

CAVEATS

Does not stage new or untracked files unless -a or git add used. Empty commits blocked by default. Hooks bypassed with --no-verify skips validation. Amending rewrites history; avoid on shared branches.

COMMIT MESSAGE GUIDELINES

Use imperative mood (e.g., 'Fix bug'). Limit subject to 50 chars, body to 72. Structure: subject
blank line
body. Reference issues with 'Closes #123'.

EXAMPLES

git commit -m 'Fix typo in README'
git commit -a (stage all tracked changes)
git commit --amend (edit last commit)

HISTORY

Introduced in Git 1.0.0 (2005) by Linus Torvalds. Evolved with options like --amend (v1.6.0), signing (v1.7.9), trailers (v2.0). Core to Git's distributed model, influenced by BitKeeper/Monotone.

SEE ALSO

Copied to clipboard