Multiline git commit message in VSCode
Visual Studio-CodeVisual Studio-Code Problem Overview
When commiting files using VSCode's Git integration, is there any way of writing a multiline commit message, or am I limited to a single line only?
As of now, VSCode is great at staging files. But it seems I'll still have to write most of my commit messages from the terminal.
Visual Studio-Code Solutions
Solution 1 - Visual Studio-Code
With the 0.5.0 release we now support multi line commit messages. Just hit the Enter
key to add new lines.
Solution 2 - Visual Studio-Code
While Benjamin Pasero's answer is definitely viable, do you really want to compose non-trivial commit messages within that bare-bones textbox built into the sidebar? I would rather write my commit messages within a VS Code tab instead, unlocking the editor's full power.
Setup
-
Set VS Code's default terminal to Git Bash (optional and only relevant if using Windows) by putting something like the following in your VS Code settings. Actually, just do it via the GUI instead, as stated in this answer. (Note that you can execute
cmd
orpowershell
from that terminal andbash
to get back.)"terminal.integrated.profiles.windows": { "Git Bash": { "source": "Git Bash" } }, "terminal.integrated.defaultProfile.windows": "Git Bash",
-
Set Git's default editor to VS Code, either by selecting VS Code as the default editor during Git installation or by putting something like the following in your global .gitconfig file. See this question for more detail.
[core] editor = 'C:\\Users\\your user dir\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe' --wait
-
Set VS Code up for a more enjoyable commit experience via extensions like Rewrap, Code Spell Checker, MetaGo, etc., combined with language-specific settings in the
settings.json
file in the executable's folder, e.g.:"[git-commit]": { "editor.rulers": [72, 50], "editor.wordWrap": "off" }
Usage
-
If the VS Code terminal isn't already visible, hit ctrl+` to bring it up.
-
Use it to execute
git commit -a
or whatever. -
A new tab will appear in VS Code, where you can type in your commit message.
-
When you are done, save and close that tab to complete the commit, or close the tab without saving to abort it. You can hit ctrl+` again to hide the terminal.
Action Shot
Regarding using Rewrap with multiple rulers:
> Just press Alt+q multiple times to wrap to each ruler in turn. The > ruler chosen is then remembered for that document for the rest of the > session. It cycles through the rulers in the order in which they > appear in settings; so if you have a most commonly used ruler, you > probably want to put that first.
See the documentation for more detail.
Solution 3 - Visual Studio-Code
For a convenient multiline commit message editor, install an extension called "adam-bender.commit-message-editor".
Solution 4 - Visual Studio-Code
You can configure git to use any editor. For example, if you like to use VSC editor for long commit messages, you can run the below command in the terminal:
git config --global core.editor "code --wait"
and then just commit it without "-m"
it will open a commit edit tab on VS code where you type in your long commit message. When you close that tab your commit message will be added
note: you might need to run Control + shift + P to open your command palette and install code
Git instruction for other editors: https://git-scm.com/book/en/v2/Appendix-C%3A-Git-Commands-Setup-and-Config
Solution 5 - Visual Studio-Code
If you're using command palette and prompt Git commit, there is no way to write multiple lines commit message, so yeah if your commit message is rather long use a terminal: either external one or integrated into vscode.