# Re:

2 messages from 2021-08-21 to 2021-08-21. Participants: Jeff King, TECOB270_Ganesh Pawar.
Thread: https://gitlist.dev/t/56344

## TECOB270_Ganesh Pawar, 2021-08-21 14:40

Subject: 
Message-ID: <CAAOR--EV5iixus=wY4ukO2VpE6Ktr=XtKB58FDCyUZ0OvqLuAQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAAOR--EV5iixus%3DwY4ukO2VpE6Ktr%3DXtKB58FDCyUZ0OvqLuAQ%40mail.gmail.com

```
I'm not sure if this is a bug.

To reproduce:
1. Set the contents of .git/hooks/prepare-commit-msg to this:
ˋˋˋ
#!/bin/sh

COMMIT_MSG_FILE=$1

echo "Initial Commit." > "$COMMIT_MSG_FILE"
echo "" >> "$COMMIT_MSG_FILE"
echo "# Some random comment." >> "$COMMIT_MSG_FILE"
ˋˋˋ
Notice the comment being added to the file.

2. Append a commit with the --no-edit flag.
`git commit --amend --no-edit`

The comment ("Some random comment" in this case) is included in the
final commit message, but it shouldn't right?

If I don't pass the flag and just save the commit without changing
anything, the comment isn't included. Shouldn't this be the case with
the --no-edit flag too?

```

## Jeff King, 2021-08-21 23:52

Subject: Re:
Message-ID: <YSGRwUs8oj/r2MQf@coredump.intra.peff.net>
URL: https://gitlist.dev/e/YSGRwUs8oj%2Fr2MQf%40coredump.intra.peff.net
In-Reply-To: <CAAOR--EV5iixus=wY4ukO2VpE6Ktr=XtKB58FDCyUZ0OvqLuAQ@mail.gmail.com>

```
On Sat, Aug 21, 2021 at 08:10:59PM +0530, TECOB270_Ganesh Pawar wrote:

> To reproduce:
> 1. Set the contents of .git/hooks/prepare-commit-msg to this:
> ˋˋˋ
> #!/bin/sh
> 
> COMMIT_MSG_FILE=$1
> 
> echo "Initial Commit." > "$COMMIT_MSG_FILE"
> echo "" >> "$COMMIT_MSG_FILE"
> echo "# Some random comment." >> "$COMMIT_MSG_FILE"
> ˋˋˋ
> Notice the comment being added to the file.
> 
> 2. Append a commit with the --no-edit flag.
> `git commit --amend --no-edit`
> 
> The comment ("Some random comment" in this case) is included in the
> final commit message, but it shouldn't right?
> 
> If I don't pass the flag and just save the commit without changing
> anything, the comment isn't included. Shouldn't this be the case with
> the --no-edit flag too?

No, the behavior you're seeing is expected. Try this:

  git commit --cleanup=strip --amend --no-edit

The default for "--cleanup" is "strip" when the editor is run, and
"whitespace" otherwise. I.e., if Git did not insert comments, then it
doesn't remove them either.

If you have a hook which is inserting comments which may need to be
stripped, you may want to set the commit.cleanup config to tell Git to
always remove them (but beware that invocations like "git commit -F"
will also start stripping comments).

See "--cleanup" in "git help commit" for the possible values.

-Peff

```
