Inconsistency in commit message handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]




When creating a normal commit using `git commit -m MSG`, an additional `\n` is
appended to the end of `MSG` before going through cleanup. However when creating
a merge commit using `git merge --no-ff -m MSG BRANCH`, this additional `\n`
appears to be missing.
Under default configuration this has no impact because `commit.cleanup
= default`
is equivalent to `commit.cleanup = whitespace` when non-interactive. Therefore
the additional `\n` simply gets cleaned up and nothing happens.
However in my case it does cause some trouble. I use the
`prepare-commit-msg` hook to
inject some comments into my editor to help me write during interactive commits.
This is the hook, with all irrelevant fluff removed:
```
#!/usr/bin/env bash
COMMIT_MSG_FILE=1ドル
echo "# My additional comments" >> "$COMMIT_MSG_FILE"
```
I also set `commit.cleanup = strip` so that these comments also get
cleaned up for
non-interactive commits.
And this works for normal commits interactive, normal commits non-interactive,
merge commits interactive, but NOT merge commits non-interactive.
Since `git merge --no-ff -m MSG BRANCH` does not append a `\n`, these comments
actually clobber merge commits. `git merge --no-ff -m "Merge message"
BRANCH` ends up
having a message like this: "Merge message# My additional comments".
I hesitate to call this a bug because arguably it's just some behaviour quirks
that my hook script should handle. But I think it is fair to call this
inconsistent,
and it creates surprises for the user as it did for me. I would prefer
that `git merge`
adds this `\n` too.
---
What did you do before the bug happened? (Steps to reproduce your issue)
1. Add the aforementioned `prepare-commit-msg` hook.
2. Set `commit.cleanup = strip`.
3. Run `git merge --no-ff -m "Merge message" BRANCH`.
4. Run `git show`
What did you expect to happen? (Expected behavior)
The merge commit has message "Merge message".
What happened instead? (Actual behavior)
The merge commit has message "Merge message# My additional comments".
What's different between what you expected and what actually happened?
My injected comments did not appear on a new line, and hence failed to
get cleaned up.
[System Info]
git version:
git version 2.55.0
cpu: x86_64
built from commit: e9019fcafe0040228b8631c30f97ae1adb61bcdc
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
rust: enabled
feature: fsmonitor--daemon
gettext: enabled
libcurl: 8.21.0
OpenSSL: OpenSSL 3.6.3 9 Jun 2026
zlib-ng: 2.3.3
SHA-1: SHA1_DC
SHA-256: SHA256_BLK
default-ref-format: files
default-hash: sha1
uname: Linux 6.18.48-1-lts #1 SMP PREEMPT_DYNAMIC 2026年8月28日
11:47:30 +0000 x86_64
compiler info: gnuc: 16.1
libc info: glibc: 2.44
$SHELL (typically, interactive shell): /usr/bin/bash
[Enabled Hooks]
prepare-commit-msg

[Index of Archives] [Linux Kernel Development] [Gcc Help] [IETF Annouce] [DCCP] [Netdev] [Networking] [Security] [V4L] [Bugtraq] [Yosemite] [MIPS Linux] [ARM Linux] [Linux Security] [Linux RAID] [Linux SCSI] [Fedora Users]

(追記) (追記ここまで)
Powered by Linux

AltStyle によって変換されたページ (->オリジナル) /