git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* commiting a change from command line with newlines.
@ 2020-07-03  4:22 Tomas
  2020-07-03  4:54 ` Junio C Hamano
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tomas @ 2020-07-03  4:22 UTC (permalink / raw)
  To: git

Hello,

I'm trying to write stanzas in my commit message, and naturally the ASCII newline character is the best tool for this, beautifully integrated throughout my whole system, from my keyboard to my screen.

My question is, how can I add a newline from the git command line without opening an external program like vi, atom, notepad, word etc...

Since I'm using a unix like system I even tried with pipes (and xargs, the necessary evil) but with something like "printf "a\nb" | xargs git commit -m" b gets interpreted as something else. 

Does anybody know of a way to adorn a commit message with newlines in a single git commit command? 
Thanks in advance.





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: commiting a change from command line with newlines.
  2020-07-03  4:22 commiting a change from command line with newlines Tomas
@ 2020-07-03  4:54 ` Junio C Hamano
  2020-07-03  4:55 ` brian m. carlson
  2020-07-03  5:14 ` Kevin Daudt
  2 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2020-07-03  4:54 UTC (permalink / raw)
  To: Tomas; +Cc: git

Tomas <correo@tomaszubiri.com> writes:

> I'm trying to write stanzas in my commit message, and naturally
> the ASCII newline character is the best tool for this, beautifully
> integrated throughout my whole system, from my keyboard to my
> screen.
>
> My question is, how can I add a newline from the git command line
> without opening an external program like vi, atom, notepad, word
> etc...

Just like you pass any command an argument that has newline(s) in
it, e.g.

    $ git commit -s -m 'area: teach gostak to distim doshes[ENTER]
    > [ENTER]
    > Gostaks inherently want to distim doshes, so let them do so[ENTER]
    > freely.' -a[ENTER]

you can give such a string to "git commit" as an argument to its
"-m" option.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: commiting a change from command line with newlines.
  2020-07-03  4:22 commiting a change from command line with newlines Tomas
  2020-07-03  4:54 ` Junio C Hamano
@ 2020-07-03  4:55 ` brian m. carlson
  2020-07-03  5:14 ` Kevin Daudt
  2 siblings, 0 replies; 4+ messages in thread
From: brian m. carlson @ 2020-07-03  4:55 UTC (permalink / raw)
  To: Tomas; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 1715 bytes --]

On 2020-07-03 at 04:22:09, Tomas wrote:
> Hello,
> 
> I'm trying to write stanzas in my commit message, and naturally the ASCII newline character is the best tool for this, beautifully integrated throughout my whole system, from my keyboard to my screen.
> 
> My question is, how can I add a newline from the git command line without opening an external program like vi, atom, notepad, word etc...
> 
> Since I'm using a unix like system I even tried with pipes (and xargs, the necessary evil) but with something like "printf "a\nb" | xargs git commit -m" b gets interpreted as something else.
> 
> Does anybody know of a way to adorn a commit message with newlines in a single git commit command?

It's generally possible to do this with a multi-line string.  You can
write something like this:

$ git commit -m 'git: make boring change

Add this boring change so that people are put to sleep.  They will be
able to sleep well and therefore awake refreshed.
'

Your shell will usually indicate some sort of continuation prompt due to
the multi-line string, and you can simply close the single quote when
you're done.  This also works in shell scripts, and our testsuite uses
this syntax extensively.

If you need to insert a single quote, you can do this:

$ git commit -m 'git: make boring change

Add this boring change so that people are put to sleep.  They'\''ll be
able to sleep well and therefore awake refreshed.
'

Of course, the benefit to using an editor is that you can edit your
changes, so you may find that while this works, dealing with the
occasional typing mistake is inconvenient.
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 263 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: commiting a change from command line with newlines.
  2020-07-03  4:22 commiting a change from command line with newlines Tomas
  2020-07-03  4:54 ` Junio C Hamano
  2020-07-03  4:55 ` brian m. carlson
@ 2020-07-03  5:14 ` Kevin Daudt
  2 siblings, 0 replies; 4+ messages in thread
From: Kevin Daudt @ 2020-07-03  5:14 UTC (permalink / raw)
  To: Tomas; +Cc: git

On Fri, Jul 03, 2020 at 01:22:09AM -0300, Tomas wrote:
> Hello,
> 
> I'm trying to write stanzas in my commit message, and naturally the ASCII newline character is the best tool for this, beautifully integrated throughout my whole system, from my keyboard to my screen.
> 
> My question is, how can I add a newline from the git command line without opening an external program like vi, atom, notepad, word etc...
> 
> Since I'm using a unix like system I even tried with pipes (and xargs, the necessary evil) but with something like "printf "a\nb" | xargs git commit -m" b gets interpreted as something else. 
> 
> Does anybody know of a way to adorn a commit message with newlines in a single git commit command? 
> Thanks in advance.
> 

git commit accepts multiple `-m` arguments, where each message will be
concattenaed with two newline characters.

So `git commit -m "add foo to bar" -m "foo is necessary to allow bar to
..." -m "baz would not work in this case because.."`

Would turn out as:

> add foo to bar
>
> foo is necessary to allow bar to...
>
> baz would not work in this case beacuse..

Hope this helps,

Kevin

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-07-03  5:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-03  4:22 commiting a change from command line with newlines Tomas
2020-07-03  4:54 ` Junio C Hamano
2020-07-03  4:55 ` brian m. carlson
2020-07-03  5:14 ` Kevin Daudt

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).