DEV Community

Quoc-Hung Hoang
Quoc-Hung Hoang

Posted on

Commit message with title and body with one-liner git command

When you use git, one of the most frequent used command is

git commit -m "my commit message"
Enter fullscreen mode Exit fullscreen mode

But most of the time, you would give a more meaningful commit message. Meaningful I mean here is that the message should consist of subject line (a short description of your changes in code) and body (to give more detailed description of what you did)

Today I learn that git commit accept multiple message flag 😉
If you run this command

git commit -m "subject line" -m "commit description"
Enter fullscreen mode Exit fullscreen mode

It will result in this

Author: hunghoang-saritasa <>
Date:   Thu Aug 11 16:29:07 2022 +0700

    Subject line

    Commit message
Enter fullscreen mode Exit fullscreen mode

This new finding helps me save time a lot. No need to open a vim editor when committing message with subject and body. And actually the git documentation do mention it.

Bonus: Another way to achieve this commit message structure is opening quotes then press enter and closing the commit with quotes again
Image description

Top comments (0)