Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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".
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top