{"thread":{"id":"56344","subject":"Re:","startedAt":"2021-08-21T14:41:12Z","lastAt":"2021-08-21T23:52:36Z","messageCount":2,"participants":["Jeff King","TECOB270_Ganesh Pawar"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"433544","messageId":"CAAOR--EV5iixus=wY4ukO2VpE6Ktr=XtKB58FDCyUZ0OvqLuAQ@mail.gmail.com","threadId":"56344","inReplyTo":null,"subject":"","fromName":"TECOB270_Ganesh Pawar","fromEmail":"pawarg256@gmail.com","sentAt":"2021-08-21T14:40:59Z","receivedAt":"2021-08-21T14:41:12Z","isPatch":false,"sender":{"key":"pawarg256@gmail.com","avatar":null},"body":"I'm not sure if this is a bug.\n\nTo reproduce:\n1. Set the contents of .git/hooks/prepare-commit-msg to this:\n```\n#!/bin/sh\n\nCOMMIT_MSG_FILE=$1\n\necho \"Initial Commit.\" > \"$COMMIT_MSG_FILE\"\necho \"\" >> \"$COMMIT_MSG_FILE\"\necho \"# Some random comment.\" >> \"$COMMIT_MSG_FILE\"\n```\nNotice the comment being added to the file.\n\n2. Append a commit with the --no-edit flag.\n`git commit --amend --no-edit`\n\nThe comment (\"Some random comment\" in this case) is included in the\nfinal commit message, but it shouldn't right?\n\nIf I don't pass the flag and just save the commit without changing\nanything, the comment isn't included. Shouldn't this be the case with\nthe --no-edit flag too?\n"},{"id":"433316","messageId":"YSGRwUs8oj/r2MQf@coredump.intra.peff.net","threadId":"56344","inReplyTo":"CAAOR--EV5iixus=wY4ukO2VpE6Ktr=XtKB58FDCyUZ0OvqLuAQ@mail.gmail.com","subject":"Re:","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2021-08-21T23:52:33Z","receivedAt":"2021-08-21T23:52:36Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Aug 21, 2021 at 08:10:59PM +0530, TECOB270_Ganesh Pawar wrote:\n\n> To reproduce:\n> 1. Set the contents of .git/hooks/prepare-commit-msg to this:\n> ```\n> #!/bin/sh\n> \n> COMMIT_MSG_FILE=$1\n> \n> echo \"Initial Commit.\" > \"$COMMIT_MSG_FILE\"\n> echo \"\" >> \"$COMMIT_MSG_FILE\"\n> echo \"# Some random comment.\" >> \"$COMMIT_MSG_FILE\"\n> ```\n> Notice the comment being added to the file.\n> \n> 2. Append a commit with the --no-edit flag.\n> `git commit --amend --no-edit`\n> \n> The comment (\"Some random comment\" in this case) is included in the\n> final commit message, but it shouldn't right?\n> \n> If I don't pass the flag and just save the commit without changing\n> anything, the comment isn't included. Shouldn't this be the case with\n> the --no-edit flag too?\n\nNo, the behavior you're seeing is expected. Try this:\n\n  git commit --cleanup=strip --amend --no-edit\n\nThe default for \"--cleanup\" is \"strip\" when the editor is run, and\n\"whitespace\" otherwise. I.e., if Git did not insert comments, then it\ndoesn't remove them either.\n\nIf you have a hook which is inserting comments which may need to be\nstripped, you may want to set the commit.cleanup config to tell Git to\nalways remove them (but beware that invocations like \"git commit -F\"\nwill also start stripping comments).\n\nSee \"--cleanup\" in \"git help commit\" for the possible values.\n\n-Peff\n"}]}