fmt-merge-msg Git Command Guide
The git fmt-merge-msg command is used to produce a formatted commit message suitable for merge commits. It takes the list of merged objects and generates a message describing the merge, typically used internally by git merge but can be used standalone.
git fmt-merge-msg Syntax:
Section titled “git fmt-merge-msg Syntax:”git fmt-merge-msg [-m <message>] [--into-name <branch>] [--log[=<n>] | --no-log] [-F <file>]Options:
Section titled “Options:”| Option | Description |
|---|---|
| —log[= | Include commit descriptions in message (default 20) |
| —no-log | Exclude commit descriptions |
| -m | Use custom message instead of branch names |
| —into-name | Specify target branch name |
| -F | Read merged objects from file instead of stdin |
| —[no-]summary | Deprecated synonyms for —log/—no-log |
Parameters:
Section titled “Parameters:”| Parameter | Description |
|---|---|
| (stdin) | List of merged objects/commit IDs |
git fmt-merge-msg Command Samples:
Section titled “git fmt-merge-msg Command Samples:”Basic merge message
Section titled “Basic merge message”git fmt-merge-msg < merge-refs.listGenerate merge commit message from list of refs in file.
Include commit descriptions
Section titled “Include commit descriptions”cat refs.txt | git fmt-merge-msg --logGenerate merge message with one-line commit descriptions.
Custom message with descriptions
Section titled “Custom message with descriptions”git fmt-merge-msg --log --message "Implement feature X"Use custom message with commit descriptions.
Specify target branch
Section titled “Specify target branch”git fmt-merge-msg --into-name main --log < merge-input.txtSpecify target branch name explicitly.
Limit log entries
Section titled “Limit log entries”cat merge-refs | git fmt-merge-msg --log=10Include only 10 commit descriptions in message.
Read from stdin with no log
Section titled “Read from stdin with no log”echo -e "abc123\ndef456" | git fmt-merge-msg --no-logGenerate merge message without commit descriptions.
Use with git merge output
Section titled “Use with git merge output”git fmt-merge-msg --log --message "Merge pull request" < merge-refs.txtGenerate message as used internally by git merge.
How do I generate a merge commit message with descriptions?
Section titled “How do I generate a merge commit message with descriptions?”To include commit descriptions, use —log option:
git fmt-merge-msg --log < merge-ref-listHow can I customize the merge message?
Section titled “How can I customize the merge message?”To use a custom message instead of branch names, use —message:
git fmt-merge-msg --message "Feature implementation" --logHow do I limit the number of commit descriptions?
Section titled “How do I limit the number of commit descriptions?”To limit descriptions, specify a number with —log:
git fmt-merge-msg --log=5How can I read merge refs from a file?
Section titled “How can I read merge refs from a file?”To read from a file instead of stdin, use -F:
git fmt-merge-msg -F merge-refs.txt --logHow do I specify the target branch name?
Section titled “How do I specify the target branch name?”To specify which branch is being merged into, use —into-name:
git fmt-merge-msg --into-name develop --logWhat’s the difference between —log and —no-log?
Section titled “What’s the difference between —log and —no-log?”—log includes one-line commit descriptions, —no-log only shows branch names but no individual commit details.
How is this used internally by git merge?
Section titled “How is this used internally by git merge?”git merge calls fmt-merge-msg to format the commit message when completing a merge operation, passing appropriate options and merge information.
Can I suppress branch destination in messages?
Section titled “Can I suppress branch destination in messages?”Configure merge.suppressDest to omit “into
Applications of the git fmt-merge-msg command
Section titled “Applications of the git fmt-merge-msg command”- Scripting custom merge workflows with formatted messages
- Generating merge commit messages for automation tools
- Creating merge messages for complex multi-branch merges
- Debugging merge operations by examining generated messages
- Integrating merge message generation in CI/CD pipelines