git commit -a --file message.txt; git format-patch removes newlines from message.txt
When using a text file for a commit message git commit -a --file message.txt
and then generating a patch file with git format-patch
the commit message get written with all newlines stripped (Linux).
Seems like the culprit is the format-patch
By default, the subject of a single patch is "[PATCH] " followed by
the concatenation of lines from the commit message up to the first
blank line (see the DISCUSSION section of git-commit[1]).
I could not find yet the way to change this default behaviour. Is there a way?
How can I change it to take the commit message verbatim from the message.txt
and put it into the generated 0001-xxx.patch file?
so from
* change 1
* change 2
it goes to
* change 1 * change 2
when running git format-patch
and I obviously want it to keep the newlines.
This is how I am checking the result:
less message.txt
git commit -a --file message.txt
git format-patch -1 my_branch
less *.patch
To clarify and confirm, the git show
shows the commit message with intact newlines. I am using Linux term.
EDIT: rewritten the question to reflect the format-patch at the core of the problem
EDIT2: I have found a workaround: in case there is an empty line after the first line in the message.txt the rest of the file format is preserved.
So this is how I have to format the message.txt
first line
empty line
* change 1
* change 2
With this I have solved my immediate problem but not sure if this is the right thing to do.
git
|
show 2 more comments
When using a text file for a commit message git commit -a --file message.txt
and then generating a patch file with git format-patch
the commit message get written with all newlines stripped (Linux).
Seems like the culprit is the format-patch
By default, the subject of a single patch is "[PATCH] " followed by
the concatenation of lines from the commit message up to the first
blank line (see the DISCUSSION section of git-commit[1]).
I could not find yet the way to change this default behaviour. Is there a way?
How can I change it to take the commit message verbatim from the message.txt
and put it into the generated 0001-xxx.patch file?
so from
* change 1
* change 2
it goes to
* change 1 * change 2
when running git format-patch
and I obviously want it to keep the newlines.
This is how I am checking the result:
less message.txt
git commit -a --file message.txt
git format-patch -1 my_branch
less *.patch
To clarify and confirm, the git show
shows the commit message with intact newlines. I am using Linux term.
EDIT: rewritten the question to reflect the format-patch at the core of the problem
EDIT2: I have found a workaround: in case there is an empty line after the first line in the message.txt the rest of the file format is preserved.
So this is how I have to format the message.txt
first line
empty line
* change 1
* change 2
With this I have solved my immediate problem but not sure if this is the right thing to do.
git
What line ending characters are present inmessage.txt
?
– mkrieger1
Nov 13 '18 at 20:30
1
I'm not able to reproduce this behavior; in my tests, the newlines are preserved. Can you clarify what command or tool you're using to look at the commit message, just to make sure that isn't a factor in what is observed?
– Mark Adelsberger
Nov 13 '18 at 20:32
I just use git format-patch -1 my_branch_name; less *.patch
– Diego
Nov 13 '18 at 21:02
@mkrieger1 - not sure how to double check on your question but the message.txt was created on Linux and I am using git on the same Linux machine. So I would assume it is the UNIX line ending.
– Diego
Nov 13 '18 at 21:08
@MarkAdelsberger I have edited my question to add the information you requested
– Diego
Nov 13 '18 at 21:22
|
show 2 more comments
When using a text file for a commit message git commit -a --file message.txt
and then generating a patch file with git format-patch
the commit message get written with all newlines stripped (Linux).
Seems like the culprit is the format-patch
By default, the subject of a single patch is "[PATCH] " followed by
the concatenation of lines from the commit message up to the first
blank line (see the DISCUSSION section of git-commit[1]).
I could not find yet the way to change this default behaviour. Is there a way?
How can I change it to take the commit message verbatim from the message.txt
and put it into the generated 0001-xxx.patch file?
so from
* change 1
* change 2
it goes to
* change 1 * change 2
when running git format-patch
and I obviously want it to keep the newlines.
This is how I am checking the result:
less message.txt
git commit -a --file message.txt
git format-patch -1 my_branch
less *.patch
To clarify and confirm, the git show
shows the commit message with intact newlines. I am using Linux term.
EDIT: rewritten the question to reflect the format-patch at the core of the problem
EDIT2: I have found a workaround: in case there is an empty line after the first line in the message.txt the rest of the file format is preserved.
So this is how I have to format the message.txt
first line
empty line
* change 1
* change 2
With this I have solved my immediate problem but not sure if this is the right thing to do.
git
When using a text file for a commit message git commit -a --file message.txt
and then generating a patch file with git format-patch
the commit message get written with all newlines stripped (Linux).
Seems like the culprit is the format-patch
By default, the subject of a single patch is "[PATCH] " followed by
the concatenation of lines from the commit message up to the first
blank line (see the DISCUSSION section of git-commit[1]).
I could not find yet the way to change this default behaviour. Is there a way?
How can I change it to take the commit message verbatim from the message.txt
and put it into the generated 0001-xxx.patch file?
so from
* change 1
* change 2
it goes to
* change 1 * change 2
when running git format-patch
and I obviously want it to keep the newlines.
This is how I am checking the result:
less message.txt
git commit -a --file message.txt
git format-patch -1 my_branch
less *.patch
To clarify and confirm, the git show
shows the commit message with intact newlines. I am using Linux term.
EDIT: rewritten the question to reflect the format-patch at the core of the problem
EDIT2: I have found a workaround: in case there is an empty line after the first line in the message.txt the rest of the file format is preserved.
So this is how I have to format the message.txt
first line
empty line
* change 1
* change 2
With this I have solved my immediate problem but not sure if this is the right thing to do.
git
git
edited Nov 14 '18 at 0:04
Diego
asked Nov 13 '18 at 20:23
DiegoDiego
458412
458412
What line ending characters are present inmessage.txt
?
– mkrieger1
Nov 13 '18 at 20:30
1
I'm not able to reproduce this behavior; in my tests, the newlines are preserved. Can you clarify what command or tool you're using to look at the commit message, just to make sure that isn't a factor in what is observed?
– Mark Adelsberger
Nov 13 '18 at 20:32
I just use git format-patch -1 my_branch_name; less *.patch
– Diego
Nov 13 '18 at 21:02
@mkrieger1 - not sure how to double check on your question but the message.txt was created on Linux and I am using git on the same Linux machine. So I would assume it is the UNIX line ending.
– Diego
Nov 13 '18 at 21:08
@MarkAdelsberger I have edited my question to add the information you requested
– Diego
Nov 13 '18 at 21:22
|
show 2 more comments
What line ending characters are present inmessage.txt
?
– mkrieger1
Nov 13 '18 at 20:30
1
I'm not able to reproduce this behavior; in my tests, the newlines are preserved. Can you clarify what command or tool you're using to look at the commit message, just to make sure that isn't a factor in what is observed?
– Mark Adelsberger
Nov 13 '18 at 20:32
I just use git format-patch -1 my_branch_name; less *.patch
– Diego
Nov 13 '18 at 21:02
@mkrieger1 - not sure how to double check on your question but the message.txt was created on Linux and I am using git on the same Linux machine. So I would assume it is the UNIX line ending.
– Diego
Nov 13 '18 at 21:08
@MarkAdelsberger I have edited my question to add the information you requested
– Diego
Nov 13 '18 at 21:22
What line ending characters are present in
message.txt
?– mkrieger1
Nov 13 '18 at 20:30
What line ending characters are present in
message.txt
?– mkrieger1
Nov 13 '18 at 20:30
1
1
I'm not able to reproduce this behavior; in my tests, the newlines are preserved. Can you clarify what command or tool you're using to look at the commit message, just to make sure that isn't a factor in what is observed?
– Mark Adelsberger
Nov 13 '18 at 20:32
I'm not able to reproduce this behavior; in my tests, the newlines are preserved. Can you clarify what command or tool you're using to look at the commit message, just to make sure that isn't a factor in what is observed?
– Mark Adelsberger
Nov 13 '18 at 20:32
I just use git format-patch -1 my_branch_name; less *.patch
– Diego
Nov 13 '18 at 21:02
I just use git format-patch -1 my_branch_name; less *.patch
– Diego
Nov 13 '18 at 21:02
@mkrieger1 - not sure how to double check on your question but the message.txt was created on Linux and I am using git on the same Linux machine. So I would assume it is the UNIX line ending.
– Diego
Nov 13 '18 at 21:08
@mkrieger1 - not sure how to double check on your question but the message.txt was created on Linux and I am using git on the same Linux machine. So I would assume it is the UNIX line ending.
– Diego
Nov 13 '18 at 21:08
@MarkAdelsberger I have edited my question to add the information you requested
– Diego
Nov 13 '18 at 21:22
@MarkAdelsberger I have edited my question to add the information you requested
– Diego
Nov 13 '18 at 21:22
|
show 2 more comments
2 Answers
2
active
oldest
votes
Git doesn't offer an option to change this. git format-patch
needs a subject for the patches it formats, since they are essentially email messages. As such, it has to assume some format for the commit messages.
The standard Git format for commit message is that there is a short summary on the first line, a blank line, and then an optional (but recommended) longer description, optionally with trailers separated by a blank line. There are many, many tools, including parts of Git, that assume this format, and I highly recommend that you follow it.
The "by default" text you mentioned above means that you can use the --subject-prefix
option to customize the [PATCH]
portion of the message, not the selection of the subject portion of the email.
just to confirm - as I have added an empty line after the first (subject) line the rest of the message was indeed formatted "as is" by format-patch
– Diego
Nov 14 '18 at 13:59
add a comment |
You can use commit templates.
I don't know if that suitable for you since you might need a different message per commit but still useful if not others can benefit from that as well.
git commit.template
create a commit template file with your content
# set the commit template in your global git config
git config --global commit.template <.git-commit-template.txt file path>Now your
~/.gitconfig
should contain:[commit]
template = <.git-commit-template.txt file path>If you wish to use empty commit
# If you allow empty commit messages set
git config --global commit.cleanup strip
--cleanup=<mode>
This option sets how the commit message is cleaned up.
The<mode>
can be one ofverbatim
,whitespace
,strip
, anddefault
.
The
default
mode will strip leading and trailing empty lines and #commentary from the commit message only if the message is to be edited. Otherwise only whitespace removed.
-------------------------------------------------------------------
| Mode | Description |
---------------|--------------------------------------------------|
| verbatim | does not change message at all, |
| whitespace | removes just leading/trailing whitespace lines |
| strip | removes both whitespace and commentary. |
-------------------------------------------------------------------
Thanks for the post! Not sure if this is relevant at all because the problem is with the git format-patch. 'git show' shows proper newlines. I have edited my question to clarify on that since your answer was posted.
– Diego
Nov 13 '18 at 23:05
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288937%2fgit-commit-a-file-message-txt-git-format-patch-removes-newlines-from-message%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Git doesn't offer an option to change this. git format-patch
needs a subject for the patches it formats, since they are essentially email messages. As such, it has to assume some format for the commit messages.
The standard Git format for commit message is that there is a short summary on the first line, a blank line, and then an optional (but recommended) longer description, optionally with trailers separated by a blank line. There are many, many tools, including parts of Git, that assume this format, and I highly recommend that you follow it.
The "by default" text you mentioned above means that you can use the --subject-prefix
option to customize the [PATCH]
portion of the message, not the selection of the subject portion of the email.
just to confirm - as I have added an empty line after the first (subject) line the rest of the message was indeed formatted "as is" by format-patch
– Diego
Nov 14 '18 at 13:59
add a comment |
Git doesn't offer an option to change this. git format-patch
needs a subject for the patches it formats, since they are essentially email messages. As such, it has to assume some format for the commit messages.
The standard Git format for commit message is that there is a short summary on the first line, a blank line, and then an optional (but recommended) longer description, optionally with trailers separated by a blank line. There are many, many tools, including parts of Git, that assume this format, and I highly recommend that you follow it.
The "by default" text you mentioned above means that you can use the --subject-prefix
option to customize the [PATCH]
portion of the message, not the selection of the subject portion of the email.
just to confirm - as I have added an empty line after the first (subject) line the rest of the message was indeed formatted "as is" by format-patch
– Diego
Nov 14 '18 at 13:59
add a comment |
Git doesn't offer an option to change this. git format-patch
needs a subject for the patches it formats, since they are essentially email messages. As such, it has to assume some format for the commit messages.
The standard Git format for commit message is that there is a short summary on the first line, a blank line, and then an optional (but recommended) longer description, optionally with trailers separated by a blank line. There are many, many tools, including parts of Git, that assume this format, and I highly recommend that you follow it.
The "by default" text you mentioned above means that you can use the --subject-prefix
option to customize the [PATCH]
portion of the message, not the selection of the subject portion of the email.
Git doesn't offer an option to change this. git format-patch
needs a subject for the patches it formats, since they are essentially email messages. As such, it has to assume some format for the commit messages.
The standard Git format for commit message is that there is a short summary on the first line, a blank line, and then an optional (but recommended) longer description, optionally with trailers separated by a blank line. There are many, many tools, including parts of Git, that assume this format, and I highly recommend that you follow it.
The "by default" text you mentioned above means that you can use the --subject-prefix
option to customize the [PATCH]
portion of the message, not the selection of the subject portion of the email.
answered Nov 14 '18 at 0:39
brian m. carlsonbrian m. carlson
1,34618
1,34618
just to confirm - as I have added an empty line after the first (subject) line the rest of the message was indeed formatted "as is" by format-patch
– Diego
Nov 14 '18 at 13:59
add a comment |
just to confirm - as I have added an empty line after the first (subject) line the rest of the message was indeed formatted "as is" by format-patch
– Diego
Nov 14 '18 at 13:59
just to confirm - as I have added an empty line after the first (subject) line the rest of the message was indeed formatted "as is" by format-patch
– Diego
Nov 14 '18 at 13:59
just to confirm - as I have added an empty line after the first (subject) line the rest of the message was indeed formatted "as is" by format-patch
– Diego
Nov 14 '18 at 13:59
add a comment |
You can use commit templates.
I don't know if that suitable for you since you might need a different message per commit but still useful if not others can benefit from that as well.
git commit.template
create a commit template file with your content
# set the commit template in your global git config
git config --global commit.template <.git-commit-template.txt file path>Now your
~/.gitconfig
should contain:[commit]
template = <.git-commit-template.txt file path>If you wish to use empty commit
# If you allow empty commit messages set
git config --global commit.cleanup strip
--cleanup=<mode>
This option sets how the commit message is cleaned up.
The<mode>
can be one ofverbatim
,whitespace
,strip
, anddefault
.
The
default
mode will strip leading and trailing empty lines and #commentary from the commit message only if the message is to be edited. Otherwise only whitespace removed.
-------------------------------------------------------------------
| Mode | Description |
---------------|--------------------------------------------------|
| verbatim | does not change message at all, |
| whitespace | removes just leading/trailing whitespace lines |
| strip | removes both whitespace and commentary. |
-------------------------------------------------------------------
Thanks for the post! Not sure if this is relevant at all because the problem is with the git format-patch. 'git show' shows proper newlines. I have edited my question to clarify on that since your answer was posted.
– Diego
Nov 13 '18 at 23:05
add a comment |
You can use commit templates.
I don't know if that suitable for you since you might need a different message per commit but still useful if not others can benefit from that as well.
git commit.template
create a commit template file with your content
# set the commit template in your global git config
git config --global commit.template <.git-commit-template.txt file path>Now your
~/.gitconfig
should contain:[commit]
template = <.git-commit-template.txt file path>If you wish to use empty commit
# If you allow empty commit messages set
git config --global commit.cleanup strip
--cleanup=<mode>
This option sets how the commit message is cleaned up.
The<mode>
can be one ofverbatim
,whitespace
,strip
, anddefault
.
The
default
mode will strip leading and trailing empty lines and #commentary from the commit message only if the message is to be edited. Otherwise only whitespace removed.
-------------------------------------------------------------------
| Mode | Description |
---------------|--------------------------------------------------|
| verbatim | does not change message at all, |
| whitespace | removes just leading/trailing whitespace lines |
| strip | removes both whitespace and commentary. |
-------------------------------------------------------------------
Thanks for the post! Not sure if this is relevant at all because the problem is with the git format-patch. 'git show' shows proper newlines. I have edited my question to clarify on that since your answer was posted.
– Diego
Nov 13 '18 at 23:05
add a comment |
You can use commit templates.
I don't know if that suitable for you since you might need a different message per commit but still useful if not others can benefit from that as well.
git commit.template
create a commit template file with your content
# set the commit template in your global git config
git config --global commit.template <.git-commit-template.txt file path>Now your
~/.gitconfig
should contain:[commit]
template = <.git-commit-template.txt file path>If you wish to use empty commit
# If you allow empty commit messages set
git config --global commit.cleanup strip
--cleanup=<mode>
This option sets how the commit message is cleaned up.
The<mode>
can be one ofverbatim
,whitespace
,strip
, anddefault
.
The
default
mode will strip leading and trailing empty lines and #commentary from the commit message only if the message is to be edited. Otherwise only whitespace removed.
-------------------------------------------------------------------
| Mode | Description |
---------------|--------------------------------------------------|
| verbatim | does not change message at all, |
| whitespace | removes just leading/trailing whitespace lines |
| strip | removes both whitespace and commentary. |
-------------------------------------------------------------------
You can use commit templates.
I don't know if that suitable for you since you might need a different message per commit but still useful if not others can benefit from that as well.
git commit.template
create a commit template file with your content
# set the commit template in your global git config
git config --global commit.template <.git-commit-template.txt file path>Now your
~/.gitconfig
should contain:[commit]
template = <.git-commit-template.txt file path>If you wish to use empty commit
# If you allow empty commit messages set
git config --global commit.cleanup strip
--cleanup=<mode>
This option sets how the commit message is cleaned up.
The<mode>
can be one ofverbatim
,whitespace
,strip
, anddefault
.
The
default
mode will strip leading and trailing empty lines and #commentary from the commit message only if the message is to be edited. Otherwise only whitespace removed.
-------------------------------------------------------------------
| Mode | Description |
---------------|--------------------------------------------------|
| verbatim | does not change message at all, |
| whitespace | removes just leading/trailing whitespace lines |
| strip | removes both whitespace and commentary. |
-------------------------------------------------------------------
answered Nov 13 '18 at 22:04
CodeWizardCodeWizard
52.9k127096
52.9k127096
Thanks for the post! Not sure if this is relevant at all because the problem is with the git format-patch. 'git show' shows proper newlines. I have edited my question to clarify on that since your answer was posted.
– Diego
Nov 13 '18 at 23:05
add a comment |
Thanks for the post! Not sure if this is relevant at all because the problem is with the git format-patch. 'git show' shows proper newlines. I have edited my question to clarify on that since your answer was posted.
– Diego
Nov 13 '18 at 23:05
Thanks for the post! Not sure if this is relevant at all because the problem is with the git format-patch. 'git show' shows proper newlines. I have edited my question to clarify on that since your answer was posted.
– Diego
Nov 13 '18 at 23:05
Thanks for the post! Not sure if this is relevant at all because the problem is with the git format-patch. 'git show' shows proper newlines. I have edited my question to clarify on that since your answer was posted.
– Diego
Nov 13 '18 at 23:05
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288937%2fgit-commit-a-file-message-txt-git-format-patch-removes-newlines-from-message%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What line ending characters are present in
message.txt
?– mkrieger1
Nov 13 '18 at 20:30
1
I'm not able to reproduce this behavior; in my tests, the newlines are preserved. Can you clarify what command or tool you're using to look at the commit message, just to make sure that isn't a factor in what is observed?
– Mark Adelsberger
Nov 13 '18 at 20:32
I just use git format-patch -1 my_branch_name; less *.patch
– Diego
Nov 13 '18 at 21:02
@mkrieger1 - not sure how to double check on your question but the message.txt was created on Linux and I am using git on the same Linux machine. So I would assume it is the UNIX line ending.
– Diego
Nov 13 '18 at 21:08
@MarkAdelsberger I have edited my question to add the information you requested
– Diego
Nov 13 '18 at 21:22