gitgit-commit

Creating a commit with a body and footer using the command line?


Is there a way to create a commit with a body and footer using the commandline?

I've always been doing it like this, however specifications like Conventional Commits also mention using a body and footer, so just curious whether these can be set via the command line?


Solution

  • Note that the -m option to git commit simply adds a new paragraph, which means it just adds a blank line. From the documentation:

    -m <msg>
    --message=<msg>
      Use the given <msg> as the commit message. If multiple -m options 
      are given, their values are concatenated as separate paragraphs.
    

    So the following commands are equivalent:

    git commit -m "Title
    
    Description.
    
    More Description.
    
    Trailer, or Footer, or whatever."
    

    and

    git commit -m "Title" -m "Description." -m "More Description." -m "Trailer, or Footer, or whatever."
    

    Note it's fairly common to write commit messages in a UI, or by typing git commit and letting Git popup your favorite editor. In this case the commit message is a just a temporary text file on your local drive, which you edit accordingly, by adding the blank lines where you want them. By convention, the first line is the title of the commit, followed by a blank line, and the rest is the description. Some conventions also add another blank line followed by a footer, or a trailer.