Today I learned that there are two main ways to provide a commit message in Git:
-m <msg>or--message=<msg>: This is the most common way, where you provide the message directly on the command line. You can use multiple-moptions, and their values will be concatenated as separate paragraphs.-F <file>or--file=<file>: This option allows you to take the commit message from a given file. If you use-as the filename, the message is read from the standard input. This is particularly useful for multi-line messages as it avoids potential issues with shell character escaping.
It’s important to note that the -m and -F options are mutually exclusive. You can only use one of them for a single commit.
✱ Example using -F
-
Create a file named
commit-message.txt:feat: Add new login featureThis commit introduces a new login system with email and password authentication.It also includes basic validation and error handling. -
Use the file in your commit command:
Terminal window git commit -F commit-message.txt