Re: commiting a change from command line with newlines.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux