5 ms·
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 edi
by fphilipe 6y ago
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
- simias 6y agoThank you for that tip, that would've saved me some annoying copy/pasting in the past!
- masklinn 6y agoI'd just C-x C-e and open the command line buffer in an editor to work on it there.
- simias 6y agoC-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.
- masklinn 6y agoIn 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).
- imglorp 6y agoOh man nice tip. I've been using bash for 30 years and never noticed that binding. "\C-x\C-e": edit-and-execute-command
- atsaloli 6y agoThat'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.
- fphilipe 6y agoSure, 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
- masklinn 6y ago> 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.
- u801e 6y agoMaybe something like fold -c -s -w 80 | git commit -F - <<EOF Fix issue Hello world... EOF
- caymanjim 6y agoThis 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-command-line-in-full-screen-editor-in-zsh https://unix.stackexchange.com/questions/6620/how-to-edit-co...
- LukeShu 6y ago> This isn't enabled by default. It is in Bash.
- Izkata 6y agoI typically just do the commit, then afterwards use `git commit --amend` to open the previous commit message in $EDITOR for updating.
- yjftsjthsd-h 6y agoI 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).
- delusional 6y agoFor this usecase git has the 'prepare-commit-msg' hook that allows you to configure this per repo.
- pkaye 6y agoHow does the script determine what the commit message should be?
- usr1106 6y agoI 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.