LinuxCommandLibrary

hg-commit

Record changes to the repository

TLDR

Commit staged files to the repository

$ hg commit
copy

Commit a specific file or directory
$ hg commit [path/to/file_or_directory]
copy

Commit with a specific message
$ hg commit [[-m|--message]] [message]
copy

Commit all files matching a specified pattern
$ hg commit [[-I|--include]] [pattern]
copy

Commit all files, excluding those that match a specified pattern
$ hg commit [[-X|--exclude]] [pattern]
copy

Commit using the interactive mode
$ hg commit [[-i|--interactive]]
copy

SYNOPSIS

hg commit [OPTION]... [FILE]...

PARAMETERS

-A, --addremove
    Add new files, remove deleted ones automatically

-m TEXT, --message TEXT
    Commit message as TEXT

-l FILE, --logfile FILE
    Read message from FILE

-r REV, --rev REV
    Commit to specific REV (updates first)

-u USER, --user USER
    Record USER as committer

-d DATE, --date DATE
    Set commit DATE

--amend
    Amend previous commit

--close-branch
    Mark branch head closed

-I, --include PATTERN
    Include files matching PATTERN

-X, --exclude PATTERN
    Exclude files matching PATTERN

-S, --subrepos
    Commit in subrepositories

--no-verify
    Skip pre-commit hooks

DESCRIPTION

The hg commit command records changes to files in a Mercurial repository, creating a new changeset.

It stages modifications, additions, or deletions specified by files or defaults to all modified files if none provided. A commit message is required, either via -m or an editor.

By default, it commits to the current working directory's parent revision on the active branch. Use options to include/exclude files, amend previous commits, or handle subrepositories.

Commits are local until pushed. Ensures atomic changesets for collaboration. Interactive mode unavailable; use hg record for patch-by-patch commits.

Ideal for versioning code, configs, or data. Integrates with hooks for validation.

CAVEATS

Must run inside repository; no files specified commits all changes. Empty message prompts editor. Amending rewrites history—avoid shared repos.

EXAMPLES

hg commit -m "Fix bug"
Commit all changes with message.

hg commit -A file.txt
Commit file.txt, auto-add/remove.

hg commit --amend -m "Better message"
Amend last commit.

EXIT STATUS

0: success.
1: aborted (editor, hooks).
>1: errors.

HISTORY

Mercurial (hg) created 2005 by Matt Mackall for scalable DVCS. commit subcommand core since v0.9b, inspired by CVS/SVN but distributed. Evolved with amend (v1.9, 2010), subrepo support.

SEE ALSO

git-commit(1), hg-status(1), hg-log(1), hg-record(1), hg-push(1)

Copied to clipboard