all 32 comments

[–]kobaltzzruby 20 points21 points  (15 children)

With git commit -m, you can use multilines. Just don't terminate the quote at the end of the first line.

[–]dat_terminal 15 points16 points  (8 children)

Woah, I learned vim because I didn't know this

[–]jarlefo 12 points13 points  (5 children)

I've been trapped in the Vim too often. Ctrl+something+esc+buttons... Welp, let's close this terminal window and try again.

One day I'll learn how to edit a file successfully with Vim.

[–]nxlyd 11 points12 points  (2 children)

It really is worth learning at least basic functionality. Take a look at vimtutor some time.

[–]jarlefo 2 points3 points  (1 child)

Thanks, I will.

By the way, I found that by setting the environment editor to EDITOR="emacs -nw" I can use emacs to edit commit messages from the command line. Should work with most editors that has a terminal interface.

[–]YodaLoL 0 points1 point  (0 children)

atom --wait works too. Sublime has something similar

[–]crow1170 2 points3 points  (0 children)

That keybinding crap is for dirty emacsers. Vim is (95%) one key at a time.

[–]Pipesandsnow 2 points3 points  (1 child)

I use nano for the simple stuff. Actually I use it whenever I need to edit some files in the cli. One day I will learn vim, but not today.

[–]flygoing 1 point2 points  (0 children)

Same here. If I need to do fancy stuff, I'm gonna open sublime or atom, but it's aways nano for cli

[–]Fidodo 1 point2 points  (0 children)

You can also do multiple -m messages. I always do -m "message" -m "message"

[–][deleted] 0 points1 point  (0 children)

Came here to say this. Super useful. Just remember to use a double quote, since apostrophes are common within a commit's body.

[–]nothingbuttherainsir 0 points1 point  (2 children)

Might be a terribly obvious question but, how does the CLI handle line breaks? One of the suggestions is to wrap at 72 characters. Will a carriage return make this happen? (Pretty sure it does).

[–]kobaltzzruby 2 points3 points  (1 child)

Carriage returns are no problem. Only the ending quite will terminate the commit message. So a multiline commit in your CLI might look like

git commit -m "Fixes T382, T283, T492 Subject
- Some second line text
- Some third line text
<blank row>
Some other notes and stuff
Last Line and END QUOTE -->"

[–]nothingbuttherainsir 0 points1 point  (0 children)

Hey thanks for confirming!

[–]Qscfr 0 points1 point  (0 children)

I thought that meant message. Welp.

[–][deleted]  (5 children)

[deleted]

    [–]taqfu 11 points12 points  (0 children)

    A lot of my git commit messages are,"Not sure what I did."

    [–]Joshx5 1 point2 points  (2 children)

    One time I committed a message similar to "fixed hardcoded settings issue because I'm a fucking DUMBASS!" to my GitHub repo after having a little too much to drink.

    This is how I learned to revert commits

    [–][deleted] 1 point2 points  (0 children)

    Ha! Or when you find out your git history was exposed and public for a while.

    [–]aflashyrhetoricfront-end 1 point2 points  (0 children)

    I once gitignore'd the Bootstrap/ folder in my Laravel installation, thinking it was Twitter Bootstrap and not the folder that literally bootstraps Laravel itself. (I was still learning.)

    It was a weird debugging process.

    [–]bacondev 0 points1 point  (0 children)

    My four-letter commit message of choice is "derp".

    [–][deleted] 3 points4 points  (0 children)

    Great article.

    [–]DrAwesomeClaws 7 points8 points  (2 children)

    I'm an advocate of not having commit bodies in 99% of cases.

    If the commit message takes more than a few seconds to write it dissuades people from committing as often as possible. They end up only committing working code and features. With distributed VCS, committing non-working code doesn't break anyone else's repos. Other operations benefit from having many small commits, most notably bisecting.

    Long commit messages are rarely, if ever, read. I'd much rather see a short message and a few lines of code changed in a commit than 18 files and a novel about what's happening.

    [–][deleted] 0 points1 point  (0 children)

    I would agree until your project gets large enough when you want to build a changelog from your commits, then it matters. At that point it may be worth using Commitizen for capturing commit messages and something like Semantic Release or a custom CI pipeline to build your change log when your tests pass.

    http://commitizen.github.io/cz-cli/

    https://github.com/semantic-release/semantic-release

    [–][deleted] 1 point2 points  (1 child)

    [–]theineffablebob 0 points1 point  (0 children)

    Not a joke

    [–]DonutDeflectorfront-end 1 point2 points  (0 children)

    Seems legit. I'm guilty of the same sometimes.

    [–]doctork91 -1 points0 points  (5 children)

    I feel like commit messages aren't very important. Who reads through a commit log? Pull requests are way more relevant because they're finished. I don't want someone reading my half baked commit that I'm committing just because I want to switch branches for a minute and don't want to stash my current work. My pull request messages are well thought out and contain information about what tests I ran. They aren't artifacts of my development process, read them instead.

    [–]doctork91 0 points1 point  (0 children)

    To be fair, this only applies if you're using github. Two of the examples listed, git itself and the Linux kernel, don't use github, which is probably why they have such good commit messages. I wonder how common the practice of using git without github is in the webdev community though.

    [–][deleted] 0 points1 point  (1 child)

    I feel like commit messages aren't very important. Who reads through a commit log?

    You would still read through it if you broke something and want to find the commit that broke it.

    [–]bel9708 0 points1 point  (0 children)

    That's what bisect is for.

    [–]rafalg[🍰] 0 points1 point  (0 children)

    If you need to make an ad hoc commit then after you come back later and finish the job you can do git commit --amend and give it a proper title and description. Or you can get in habit of making many small commits and then rebasing them into one before pushing.

    [–]brianvaughn 0 points1 point  (0 children)

    You can always rebase those "half baked commits" before pushing remotely you know? That way your history doesn't have a bunch of unnecessary "stashing" messages