{"thread":{"id":"57627","subject":"How to get the original raw commit message without removing extra leading/trailing line breaks","startedAt":"2022-03-28T05:42:29Z","lastAt":"2022-03-28T06:11:57Z","messageCount":5,"participants":["PMEase","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"452451","messageId":"1BEBB3E1-0089-44CD-8D3B-3AA424C90E48@pmease.com","threadId":"57627","inReplyTo":null,"subject":"How to get the original raw commit message without removing extra leading/trailing line breaks","fromName":"PMEase","fromEmail":"robin@pmease.com","sentAt":"2022-03-28T05:42:18Z","receivedAt":"2022-03-28T05:42:29Z","isPatch":false,"sender":{"key":"robin@pmease.com","avatar":"https://gravatar.com/avatar/820c2929481baf5f11bb7e94f3afa8344deacc0cb66ead69c70018dd51307c47?d=mp&s=160"},"body":"Hi Folks, \n\nI am using command \"git show --format=raw <commit hash>\" to get raw commit object in order to verify the GPG signature in my program to customize public key loading. However in the raw commit object, extra line breaks before and after the commit message is removed, which cause the signature verification failure as git generates the signature without removing those line breaks. \n\nSo is there any way to get the exact, original commit message? I also tried format option %B in no vail. \n\nThanks for your time. \nRobin"},{"id":"452453","messageId":"xmqq5yny62s1.fsf@gitster.g","threadId":"57627","inReplyTo":"1BEBB3E1-0089-44CD-8D3B-3AA424C90E48@pmease.com","subject":"Re: How to get the original raw commit message without removing extra leading/trailing line breaks","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-03-28T05:53:50Z","receivedAt":"2022-03-28T05:53:58Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"PMEase <robin@pmease.com> writes:\n\n[jc: wrapped overly long lines]\n\n> I am using command \"git show --format=raw <commit hash>\" to get\n> raw commit object in order to verify the GPG signature in my\n> program to customize public key loading. However in the raw commit\n> object, extra line breaks before and after the commit message is\n> removed, which cause the signature verification failure as git\n> generates the signature without removing those line breaks.\n\n\"git show --format=raw <commit object name>\" will not give \"raw\ncommit object\" to begin with.  It indents the message by four\nspaces.\n\n\"git cat-file commit <commit object name>\" is what you want, I\nthink.\n"},{"id":"452454","messageId":"5DAF0ABA-7905-491B-A1DC-291A2D7C2BB4@pmease.com","threadId":"57627","inReplyTo":"xmqq5yny62s1.fsf@gitster.g","subject":"Re: How to get the original raw commit message without removing extra leading/trailing line breaks","fromName":"PMEase","fromEmail":"robin@pmease.com","sentAt":"2022-03-28T06:01:06Z","receivedAt":"2022-03-28T06:01:28Z","isPatch":false,"sender":{"key":"robin@pmease.com","avatar":"https://gravatar.com/avatar/820c2929481baf5f11bb7e94f3afa8344deacc0cb66ead69c70018dd51307c47?d=mp&s=160"},"body":"Hi Junio, \n\nThanks for your response. \"git cat-file\" prints the commit message without leading space on each line, however extra leading/trailing line breaks of the commit message is still removed.\n\n> On Mar 28, 2022, at 1:53 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> \n> PMEase <robin@pmease.com> writes:\n> \n> [jc: wrapped overly long lines]\n> \n>> I am using command \"git show --format=raw <commit hash>\" to get\n>> raw commit object in order to verify the GPG signature in my\n>> program to customize public key loading. However in the raw commit\n>> object, extra line breaks before and after the commit message is\n>> removed, which cause the signature verification failure as git\n>> generates the signature without removing those line breaks.\n> \n> \"git show --format=raw <commit object name>\" will not give \"raw\n> commit object\" to begin with.  It indents the message by four\n> spaces.\n> \n> \"git cat-file commit <commit object name>\" is what you want, I\n> think.\n\n"},{"id":"452456","messageId":"0D9BB163-A369-47DE-A0DC-AD396FD6DBE4@pmease.com","threadId":"57627","inReplyTo":"xmqq5yny62s1.fsf@gitster.g","subject":"Re: How to get the original raw commit message without removing extra leading/trailing line breaks","fromName":"PMEase","fromEmail":"robin@pmease.com","sentAt":"2022-03-28T06:11:35Z","receivedAt":"2022-03-28T06:11:45Z","isPatch":false,"sender":{"key":"robin@pmease.com","avatar":"https://gravatar.com/avatar/820c2929481baf5f11bb7e94f3afa8344deacc0cb66ead69c70018dd51307c47?d=mp&s=160"},"body":"It also converts \\r\\n to \\n and remove all spaces in a blank line. This is reasonable for a readable commit message, but makes it impossible to verify signature in my program...\n\n> On Mar 28, 2022, at 1:53 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> \n> PMEase <robin@pmease.com> writes:\n> \n> [jc: wrapped overly long lines]\n> \n>> I am using command \"git show --format=raw <commit hash>\" to get\n>> raw commit object in order to verify the GPG signature in my\n>> program to customize public key loading. However in the raw commit\n>> object, extra line breaks before and after the commit message is\n>> removed, which cause the signature verification failure as git\n>> generates the signature without removing those line breaks.\n> \n> \"git show --format=raw <commit object name>\" will not give \"raw\n> commit object\" to begin with.  It indents the message by four\n> spaces.\n> \n> \"git cat-file commit <commit object name>\" is what you want, I\n> think.\n\n"},{"id":"452457","messageId":"xmqqy20u4ndl.fsf@gitster.g","threadId":"57627","inReplyTo":"5DAF0ABA-7905-491B-A1DC-291A2D7C2BB4@pmease.com","subject":"Re: How to get the original raw commit message without removing extra leading/trailing line breaks","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-03-28T06:11:50Z","receivedAt":"2022-03-28T06:11:57Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"PMEase <robin@pmease.com> writes:\n\n>> On Mar 28, 2022, at 1:53 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>> \n>> PMEase <robin@pmease.com> writes:\n>> \n>> [jc: wrapped overly long lines]\n>> \n>>> I am using command \"git show --format=raw <commit hash>\" to get\n>>> raw commit object in order to verify the GPG signature in my\n>>> program to customize public key loading. However in the raw commit\n>>> object, extra line breaks before and after the commit message is\n>>> removed, which cause the signature verification failure as git\n>>> generates the signature without removing those line breaks.\n>> \n>> \"git show --format=raw <commit object name>\" will not give \"raw\n>> commit object\" to begin with.  It indents the message by four\n>> spaces.\n>> \n>> \"git cat-file commit <commit object name>\" is what you want, I\n>> think.\n\n[jc: wrapped overly long lines, moved response at the end to correct\ntop-posting]\n\n> Thanks for your response. \"git cat-file\" prints the commit message\n> without leading space on each line, however extra leading/trailing\n> line breaks of the commit message is still removed.\n\nI think you are creating your commit incorrectly.  If a line is\nmissing in what cat-file prints, then the line is *NOT* in the\ncommit.  If I try the following:\n\n----- >8 --------- >8 --------- >8 --------- >8 -----\n\nC=$(\n        cat <<\\EOF | git commit-tree -p HEAD HEAD^{tree}\n\nThis \"first line\" deliberately is on the second line.\nAnd after the \"last line\" of the log message, this commit\nhas extra blank lines at the end.\n\n\nEOF\n)\n\necho \"begin\"; git cat-file commit \"$C\"; echo \"end\"\n\n----- 8< --------- 8< --------- 8< --------- 8< -----\n\nI get:\n\nbegin\ntree 5365fd773adaac0f84c4f07532eec8809f3f6f0e\nparent abf474a5dd901f28013c52155411a48fd4c09922\nauthor Junio C Hamano <gitster@pobox.com> 1648447791 -0700\ncommitter Junio C Hamano <gitster@pobox.com> 1648447791 -0700\n\n\nThis \"first line\" deliberately is on the second line.\nAnd after the \"last line\" of the log message, this commit\nhas extra blank lines at the end.\n\n\nend\n\nwhich is very much what I expect to see.\n"}]}