16

My company has a policy that all checkins to a particular project must follow a specific multi-line template for git commits. How can I most simply create a single commit message that has multiple lines from the command line in Windows?

This is almost exactly a duplicate of "Add line break to git commit -m from command line" except that this question is specific to Windows/cmd.exe, while that question is related to bash.

4 Answers 4

17

Either create a file that contains your commit message in the right format and use git commit -F <message_file>, after which you can continually edit and reuse that same file, or create a template file and use git commit -t <template_file> to open your editor with the pre-cooked template to be filled in. The second option can be made permanent by setting the commit.template configuration variable, so you don't need to use the -t ... bit on every commit. See the git commit manual page (git help commit, if your git is installed correctly, or search online) for more information.

Sign up to request clarification or add additional context in comments.

Comments

16

You can create multiline commit message like this:

C:\> git commit -m "Line 1"^
More?
More? "Line 2"^
More?
More? "Line 3"

Note, that the circumflex character is only on odd lines.

2 Comments

doesn't work to input an empty line between message title, body and footer
I like this answer anyway :)
11
git commit -m "Subject" -m "Description..."

-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.

The -m option is mutually exclusive with -c, -C, and -F.
Source: git docs

1 Comment

Underrated answer
2

You can also use interactive rebase and then reword for editing the commit's message.

Type git commit -m "doesnt really matter whats here" and then git rebase -i HEAD~1, replace pick with r or reword, save and then edit the message.

2 Comments

This is much easier than the accepted answer! Though, instead of an interactive rebase, you could save a step and use git commit --amend.
Sure! But this will work only for latest commit, rebase works for any! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.