18

TIL: git commit accepts several message flags (-m) to allow multiline commits

 3 years ago
source link: https://www.stefanjudis.com/today-i-learned/git-commit-accepts-several-message-flags-m-to-allow-multiline-commits/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

When you use git on the command line you might have used the message flag ( -m ). It allows developers to define commit messages inline when calling git commit.

git commit -m "my commit message"

I'm not the biggest fan of this approach because I prefer to edit the commit message in vim (which I only use for writing commit messages). It gives me the opportunity to double-check the files I'm committing.

Today I learned that the git commit command accepts multiple message flags. :astonished:

It turns out that you can use the -m option multiple times. The git documentation includes the following paragraph:

If multiple -m options are given, their values are concatenated as separate paragraphs

If you run the following command

git co -m "commit title" -m "commit description"

it will result in this commit.

Author: stefan judis 
<stefanjudis gmail="" com="">
 
Date:   Tue Jul 7 21:53:21 2020 +0200

    commit title

    commit description

 test.txt | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
</stefanjudis>

You can use multiple -m flags to create "multiline commits", and I have to admit that this can be very handy in some cases.

If you want to see this command in action, I shared a short terminal session on Twitter with a little video .


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK