git am should ignore something in commit message startswith "[]"?
Asked Answered
C

2

11

I have a commit with message like [Hello World]Something.
Then I use git format-patch HEAD~1 to crate a patch.
Content of patch like this:

Subject: [PATCH 1/7] [Hello World] Something.

But after I use git am to apply patch,the commit message became "Something" only,[Hello World] seems lost.
How can I keep content in "[]" after apply patch?

Chambless answered 12/11, 2012 at 6:0 Comment(0)
D
13

git am -k would prevent it from removing content in [] brackets at the beginning of the subject, but that would also keep the [PATCH 1/7] portion. git format-patch also has a -k option which would prevent it from adding that type of content allowing the subject to be preserved through a git format-patch | git am cycle.

Doublecross answered 12/11, 2012 at 6:22 Comment(0)
A
5

I had the same concern and found the solution in the link below:

http://git.661346.n2.nabble.com/Bug-Incorrect-stripping-of-the-PATCH-prefix-in-git-am-td7643405.html

We have to use "am" command with "--keep-non-patch" option. The man page describes as follows:

$ man git am

   --keep-non-patch
       Pass -b flag to git mailinfo (see git-mailinfo(1)).

$ man git mailinfo

   -b
       When -k is not in effect, all leading strings bracketed with [ and ] pairs
       are stripped.  This option limits the stripping to only the pairs whose
       bracketed string contains the word "PATCH".
Anzio answered 11/7, 2018 at 8:26 Comment(2)
Nice. Looks like that was added in git 2.6.0, so wasn't available when I wrote my answer for this.Doublecross
I could found it based on your answer. Thanks!Anzio

© 2022 - 2024 — McMap. All rights reserved.