threads / discuss / 31999

Wishlist: git commit --no-edit

Subject: Wishlist: git commit --no-edit

## tl;dr

9 messages between Nov 2, 2012 and Nov 2, 2012.

replies: 8people: 4as markdown or json

Niels Möller· Nov 2, 2012, 09:26 UTC · lore

I'd like to have a git commit option which is the opposite of --edit, to use the selected commit message as is, without invoking any editor.

Main use case I see would be
  git commit --amend --no-edit

(say you fix a typo in the previous commit which doesn't affect the commit message). Today, one can get the same effect more clumsily as

  EDITOR=touch git commit --amend
Or maybe as
  git commit --amend -C HEAD

But I'd really prefer a --no-edit option over those alternatives. And it might be useful also in combination with other options, e.g., it would make the -C option equivalent to -c --no-edit, if I understand it correctly.

Regards, /Niels

-- 
Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.
Matthieu Moy· Nov 2, 2012, 09:42 UTC · re: Niels Möller · lore

Re: Wishlist: git commit --no-edit

nisse@lysator.liu.se (Niels Möller) writes:
Show 6 quoted lines
> I'd like to have a git commit option which is the opposite of --edit, to
> use the selected commit message as is, without invoking any editor.
>
> Main use case I see would be
>
>   git commit --amend --no-edit

Err, isn't this already working? (maybe your version of Git is too old, but my 1.7.9.5 does this at least)

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Jeff King· Nov 2, 2012, 09:59 UTC · re: Matthieu Moy · lore

Re: Wishlist: git commit --no-edit

On Fri, Nov 02, 2012 at 10:42:24AM +0100, Matthieu Moy wrote:
Show 11 quoted lines
> nisse@lysator.liu.se (Niels Möller) writes:
> 
> > I'd like to have a git commit option which is the opposite of --edit, to
> > use the selected commit message as is, without invoking any editor.
> >
> > Main use case I see would be
> >
> >   git commit --amend --no-edit
> 
> Err, isn't this already working? (maybe your version of Git is too old,
> but my 1.7.9.5 does this at least)
Yup, should be working since 1.7.9.
  $ git tag --contains ':/commit: honour --no-edit' |
    sort -V |
    head -1
  v1.7.9
-Peff
Niels Möller· Nov 2, 2012, 10:07 UTC · re: Matthieu Moy · lore

Re: Wishlist: git commit --no-edit

Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
> Err, isn't this already working? (maybe your version of Git is too old,
> but my 1.7.9.5 does this at least)
It may be that I'm confused.
It doesn't work in the version I have (1.7.2.5, debian packaged).

And then I also had a quick look in the source code (of a fresh pull from https://github.com/git/git.git). In builtin/commit.c, I didn't see any no-edit flag (but I maybe it's in the OPT_BOOL magic (which is different from OPT_BOOLEAN?)).

And it's also not mentioned in Documentation/git-commit.txt or on http://kernel.org/pub/software/scm/git/docs/git-commit.html.

If commit --no-edit does work in recent versions, then all is fine, except possibly the documentation of it. Thanks.

Regards, /Niels

-- 
Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.
Matthieu Moy· Nov 2, 2012, 10:39 UTC · re: Niels Möller · lore

[PATCH] Document 'git commit --no-edit' explicitly

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
I was tempted to merge the paragraph with --edit::, but I thought this
may add confusion. The use-cases for --edit and --no-edit are really
different so I went for a separate paragraph, right below the --edit one.
 Documentation/git-commit.txt | 5 +++++
 1 file changed, 5 insertions(+)
diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 3acf2e7..44b4347 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -188,6 +188,11 @@ OPTIONS
 	commit log message unmodified.  This option lets you
 	further edit the message taken from these sources.
 
+--no-edit::
+	Use the selected commit message without launching an editor.
+	For example, `git commit --amend --no-edit` amends a commit
+	without changing its commit message.
+
 --amend::
 	Used to amend the tip of the current branch. Prepare the tree
 	object you would want to replace the latest commit as usual
-- 
1.8.0.319.g8abfee4
Niels Möller· Nov 2, 2012, 11:24 UTC · re: Matthieu Moy · lore

Re: [PATCH] Document 'git commit --no-edit' explicitly

Matthieu Moy <Matthieu.Moy@imag.fr> writes:
> +--no-edit::
> +	Use the selected commit message without launching an editor.
> +	For example, `git commit --amend --no-edit` amends a commit
> +	without changing its commit message.
Looks clear enough to me. Thanks for fixing.

Are -c --no-edit and -C really equivalent in all cases? If so, maybe you want to say that in the documentation for -C. (And if not, maybe they *ought* to be equivalent).

Regards, /Niels

-- 
Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.
Matthieu Moy· Nov 2, 2012, 11:29 UTC · re: Niels Möller · lore

Re: [PATCH] Document 'git commit --no-edit' explicitly

nisse@lysator.liu.se (Niels Möller) writes:
Show 10 quoted lines
> Matthieu Moy <Matthieu.Moy@imag.fr> writes:
>
>> +--no-edit::
>> +	Use the selected commit message without launching an editor.
>> +	For example, `git commit --amend --no-edit` amends a commit
>> +	without changing its commit message.
>
> Looks clear enough to me. Thanks for fixing.
>
> Are -c --no-edit and -C really equivalent in all cases?
I guess so, but I didn't check.
> If so, maybe you want to say that in the documentation for -C.

I don't think we should target exhaustivity in the documentation, so I'm not in favor of *adding* it. But maybe we should replace the doc with stg like:

-c <commit>::
--reedit-message=<commit>::
	Like '-C --edit'.
(it could even make sense to deprecate one of -C/-c)
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Jeff King· Nov 2, 2012, 11:53 UTC · re: Matthieu Moy · lore

Re: [PATCH] Document 'git commit --no-edit' explicitly

On Fri, Nov 02, 2012 at 11:39:30AM +0100, Matthieu Moy wrote:
> I was tempted to merge the paragraph with --edit::, but I thought this
> may add confusion. The use-cases for --edit and --no-edit are really
> different so I went for a separate paragraph, right below the --edit one.

Yeah, usually I think it would be better to keep the positive and negative forms together, but the way you have done it does seem a lot more clear to me. I think it is because the default flips based on other options. So you would be stuck writing something like:

  -e, --edit::
          Edit the commit message using `$EDITOR`. This is the default
          unless the `-F`, `-m`, or `-C` options are used; in those
          cases, `-e` or `--edit` can be used to invoke the editor.
          Likewise, `--no-edit` can be used to suppress the editor when
          using an existing commit message. For example, `git commit
          --amend --no-edit` amends a commit without changing its commit
          message.
Your split reads much better, IMHO.
Thanks.
-Peff
Jeff King· Nov 2, 2012, 12:45 UTC · lore

Re: Wishlist: git commit --no-edit

[+cc git@vger; please keep discussion on list]
On Fri, Nov 02, 2012 at 10:37:27AM -0200, Thiago Farina wrote:
Show 13 quoted lines
> >> >   git commit --amend --no-edit
> [...]
> > Yup, should be working since 1.7.9.
> [...]
> I doesn't appear in the help either:
> 
> $ git version
> git version 1.8.0.rc2
> 
> $ git commit -h 2>&1 | grep edit
>     -c, --reedit-message <commit>
>                           reuse and edit message from specified commit
>     -e, --edit            force edit of commit

Yeah, parse_options doesn't advertise negative forms of boolean options, as they are implied. I don't think it's a big deal, especially now that it is covered in more detail in the manpage.

I think changing it would probably involve adding "--no-edit" as a separate entry in the options struct.

-Peff

← back to recent threads