LinuxCommandLibrary

git-fmt-merge-msg

Format git merge commit messages

SYNOPSIS

git fmt-merge-msg [-m <message>] [--log[=<n>] | --no-log] [--[no-]branch-description] [<file>]

PARAMETERS

-m <message>
--message <message>

    Prepend custom <message> to the output

--log[=<n>]
    Append shortlog of <n> (default 20) commits from merged branches

--logshort
    Equivalent to --log=1 (single commit summary)

--no-log
    Omit commit log summaries from output

--branch-description
    Include merged branch description in message

--no-branch-description
    Exclude branch description (default if unspecified)

-h
--help

    Display help and exit

<file>
    Read merge message from file (stdin if omitted)

DESCRIPTION

git fmt-merge-msg is a low-level (plumbing) Git command that prepares and formats the default commit message for a merge operation.

It reads a merge message from standard input or a specified file, then enhances it by optionally appending summaries of commits from the merged branches (via shortlog), branch descriptions, and custom messages. This produces a standardized, informative merge commit message suitable for git commit.

Primarily invoked internally by git merge during non-interactive merges, it ensures merge messages include relevant context like "Merge branch 'feature' into main" followed by commit logs or descriptions. Users rarely invoke it directly but can for scripting or custom workflows.

Key features include controlling log verbosity (--log=<n> limits commits summarized), excluding logs (--no-log), or adding branch metadata (--branch-description). Output is sent to stdout, allowing piping to editors or commits.

CAVEATS

Plumbing command; not for interactive use. Assumes Git repository context. Output may exceed editor limits for large merges.

EXIT STATUS

0 on success; 1 on invalid input or failure.
128 if Git fails fatally.

EXAMPLE

git fmt-merge-msg < /tmp/merge-msg formats message from file.
echo 'Merge feature' | git fmt-merge-msg --log=5 --branch-description adds shortlog and description.

HISTORY

Introduced in Git 1.5.2 (2007) as part of merge improvements; enhanced in Git 1.7.6+ with --branch-description and log controls.

SEE ALSO

Copied to clipboard