Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

git-am

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?

like image 929
Sunny Avatar asked Nov 12 '12 06:11

Sunny


People also ask

What does AM command do in git?

What is git am ? git am is a super useful command which can be used for many things as it's reading and parsing the mailbox containing the commits you specify and allows you to use only parts of the extracted data such as the code diff, the autor, the message…

How do I terminate git am?

The command refuses to process new mailboxes until the current operation is finished, so if you decide to start over from scratch, run git am --abort before running the command with mailbox names.

How do I make a patch without committing?

Just make a new local branch and commit your changes there. You can always delete the branch later if you don't want it anymore, or you can keep the branch and use it for working on whatever you're doing, then merge (or rebase) it into the master branch when it's ready.


2 Answers

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.

like image 104
qqx Avatar answered Oct 05 '22 11:10

qqx


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".
like image 22
Honggyu Kim Avatar answered Oct 05 '22 11:10

Honggyu Kim