git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: Tomas <correo@tomaszubiri.com>
Cc: git <git@vger.kernel.org>
Subject: Re: commiting a change from command line with newlines.
Date: Fri, 3 Jul 2020 04:55:44 +0000	[thread overview]
Message-ID: <20200703045544.GD9782@camp.crustytoothpaste.net> (raw)
In-Reply-To: <17312e90c37.fefa495d137526.1559287962218705021@tomaszubiri.com>

[-- 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 --]

  parent reply	other threads:[~2020-07-03  4:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2020-07-03  5:14 ` Kevin Daudt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200703045544.GD9782@camp.crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=correo@tomaszubiri.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).