News for hackers. Stuff that matters.
Re:Git commit accepts several message flags (-m) to allow mu... by fphilipe on Wednesday July 08, 2020 @05:38AM (#23768348)
What's cool is that if you start with -m and add a second -m but notice that you have more to say than initially expected, you can still pass -e to open the editor with the message entered so far:

    $ git commit -m "Fix issue" -m "Lorem ipsum..." -e
Re:Git commit accepts several message flags (-m) to allow mu... by yjftsjthsd-h on Wednesday July 08, 2020 @09:45AM (#23769821)
I exploit the same trick to have a script automatically set what it thinks a commit message should be, but still pass it for human review/edit before actually committing and pushing. Come to think of it, you could easily use this to set a default message base and do things like always prefix the directory; I like my commits to be something like "modules/foo: added bar", so I could just alias gc='git commit -m "${PWD##*/}" -e' (well, something like that, but more sophisticated).
Re:Git commit accepts several message flags (-m) to allow mu... by delusional on Wednesday July 08, 2020 @11:04AM (#23770579)
For this usecase git has the 'prepare-commit-msg' hook that allows you to configure this per repo.
Re:Git commit accepts several message flags (-m) to allow mu... by pletnes on Wednesday July 08, 2020 @11:44AM (#23771010)
I use this to insert the jira issue key into the commit message.
Re:Git commit accepts several message flags (-m) to allow mu... by mtbnut on Wednesday July 08, 2020 @07:59PM (#23775607)
Smart. The dev tool I use automatically links my commits to the Jira issue that initiated the project/fix/update. The key and sha are forever linked. It does the same with Clubhouse.
Re:Git commit accepts several message flags (-m) to allow mu... by pkaye on Wednesday July 08, 2020 @04:28PM (#23773891)
How does the script determine what the commit message should be?
Re:Git commit accepts several message flags (-m) to allow mu... by usr1106 on Wednesday July 08, 2020 @05:06PM (#23774229)
I always have the issue number and short description in the branch name, e.g. foo#123-handle-new-orders.

So that might sometimes be good enough for a first automatic commit message. I typically clean the history before I submit I submit my work to review.

Re:Git commit accepts several message flags (-m) to allow mu... by simias on Wednesday July 08, 2020 @05:40AM (#23768361)
Thank you for that tip, that would've saved me some annoying copy/pasting in the past!
Re:Git commit accepts several message flags (-m) to allow mu... by masklinn on Wednesday July 08, 2020 @07:17AM (#23768787)
I'd just C-x C-e and open the command line buffer in an editor to work on it there.
Re:Git commit accepts several message flags (-m) to allow mu... by caymanjim on Wednesday July 08, 2020 @08:38AM (#23769257)
This isn't enabled by default. You have to configure zsh with some optional features. I found this on Stack Overflow:

    autoload -z edit-command-line
    zle -N edit-command-line
    bindkey "^X^E" edit-command-line
[1] https://unix.stackexchange.com/questions/6620/how-to-edit-co...
Re:Git commit accepts several message flags (-m) to allow mu... by LukeShu on Wednesday July 08, 2020 @11:41AM (#23770972)
> This isn't enabled by default.

It is in Bash.

Re:Git commit accepts several message flags (-m) to allow mu... by imglorp on Wednesday July 08, 2020 @07:24AM (#23768829)
Oh man nice tip. I've been using bash for 30 years and never noticed that binding.

    "\C-x\C-e": edit-and-execute-command
Re:Git commit accepts several message flags (-m) to allow mu... by atsaloli on Wednesday July 08, 2020 @08:32AM (#23769218)
That's right. If anyone wants to check their bindings, use:

    bind -p
or

    bind -P
For example:

    $ bind -P |grep execute
    edit-and-execute-command can be found on "\C-x\C-e".
    $
The "bind" shell built-in is detailed in the SHELL BUILTIN COMMANDS section of the "bash" manual.
Re:Git commit accepts several message flags (-m) to allow mu... by simias on Wednesday July 08, 2020 @07:21AM (#23768818)
C-x C-e doesn't do anything in my configuration but beyond that I find that editing long freeform text on the command line gets annoying fast if only because of the careful escaping you have to do, especially for nested quotes.
Re:Git commit accepts several message flags (-m) to allow mu... by masklinn on Wednesday July 08, 2020 @07:34AM (#23768886)
In zsh (and bash I think) it opens the entire line in a buffer, making it easy to edit it in ways which wouldn't really work well at the shell.

> beyond that I find that editing long freeform text on the command line gets annoying fast if only because of the careful escaping you have to do, especially for nested quotes.

Oh I agree. Here I'd suggest it for the rare case where I was expecting to write a simple commit message and end up needing a much longer one, though usually I'd just create the commit and immediately "amend" into a proper text editor (and most of the time I use a text editor directly, because rare are the commits where the short desc is sufficient).

Re:Git commit accepts several message flags (-m) to allow mu... by fphilipe on Wednesday July 08, 2020 @07:45AM (#23768938)
Sure, but how would you format your message so the lines aren't longer than 80 chars? I guess you can edit the command to read from STDIN, but that sounds much more cumbersome than passing -e:

    git commit -F- <<EOF
    Fix issue

    Hello world...
    EOF
Re:Git commit accepts several message flags (-m) to allow mu... by masklinn on Wednesday July 08, 2020 @08:06AM (#23769066)
> Sure, but how would you format your message so the lines aren't longer than 80 chars?

Put linebreaks and fill-paragraph for the later lines? You can put linebreaks in quoted shell strings, so once it's in an editor buffer there's no issue with that.

> I guess you can edit the command to read from STDIN

The use case here is "I've already started writing a commit message inline, I now realise I need more room, I don't want to bother copy/pasting stuff around".

If I know from the start that I will need more than just a shortdesc, I'll obviously be crafting the message in my editor in the first place.

Re:Git commit accepts several message flags (-m) to allow mu... by u801e on Wednesday July 08, 2020 @08:34PM (#23775815)
Maybe something like

  fold -c -s -w 80 | git commit -F - <<EOF
  Fix issue

  Hello world...
  EOF
Re:Git commit accepts several message flags (-m) to allow mu... by Izkata on Wednesday July 08, 2020 @01:32PM (#23772102)
I typically just do the commit, then afterwards use `git commit --amend` to open the previous commit message in $EDITOR for updating.