97

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.

Adelost
  • 2,343
  • 2
  • 23
  • 28
  • I raised https://github.com/microsoft/vscode/issues/85721 to make it official, comment/vote for it there. – sorin Nov 27 '19 at 19:24
  • See https://stackoverflow.com/a/72394972/836330 ("Edit git commit message in a dedicated tab") to use an editor to create commit message. – Mark May 26 '22 at 16:23

6 Answers6

80

With the 0.5.0 release we now support multi line commit messages. Just hit the Enter key to add new lines.

enter image description here

Benjamin Pasero
  • 113,622
  • 14
  • 75
  • 54
  • 8
    Is there a way to indicate if the main body is passing 72 characters or to have the message automatically wrapped so messages can follow the 50/72 rule? – Gerry Shaw Oct 29 '16 at 17:50
  • 4
    It seems multi-line commit messages aren't supported anymore in newer releases (e.g., 1.19). – Marc Jan 18 '18 at 02:15
  • Still works for me with GIT. Pressing Enter adds a newline. – Benjamin Pasero Jan 18 '18 at 06:15
  • 14
    This doesn't work for me. It says it right below the input field `Press 'Enter' to confirm, 'Escape' to cancel`. I was hoping for something like Shift-Enter or Alt-Enter to add new lines. – Vince Oct 10 '18 at 00:28
  • 5
    @Vince Look again at the picture. That's the textbox built into the sidebar (visible when the source control tab is showing). I believe you are talking about the textbox that appears temporarily when you run a commit from the command palette. – MarredCheese Jan 11 '19 at 01:27
  • This works on version 1.42.0 on Ubuntu. It also gives you a warning about the 50 character limit on the first line, and the 72 character limit on the other lines. – Greeso Feb 12 '20 at 18:04
  • It definitely works. If you can't see textbox, check "Show Commit Input" on settings. – Jongsu Liam Kim Aug 09 '21 at 14:59
53

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

  1. 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 or powershell from that terminal and bash to get back.)

    "terminal.integrated.profiles.windows": {
        "Git Bash": {
            "source": "Git Bash"
        }
    },
    "terminal.integrated.defaultProfile.windows": "Git Bash",
    
  2. 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
    
  3. 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

  1. If the VS Code terminal isn't already visible, hit ctrl+` to bring it up.

  2. Use it to execute git commit -a or whatever.

  3. A new tab will appear in VS Code, where you can type in your commit message.

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

vs code commit

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.

MarredCheese
  • 17,541
  • 8
  • 92
  • 91
  • 2
    I am surprised the vscode team did not made this happen yet. This is why I raised https://github.com/microsoft/vscode/issues/85721 and please comment there if you want to become a reality. – sorin Nov 27 '19 at 19:23
  • 2
    Changing the default terminal to bash is not necessary. – darda Jun 29 '21 at 20:14
7

The way you will enter a multiline comment with VSCode will evolve with 1.69 (June 2022)

See issue 153366:

Git commit editor input

This new experience is controlled using two new settings: git.useEditorAsCommitInput (default value is true), git.terminalGitEditor (default value is false).

Prerequisites

Open VS Code Insiders and ensure that the settings are set to their default values:

  • git.useEditorAsCommitInput is set to true
  • git.terminalGitEditor is set to false

Commit message editor

  • Open VS Code Insiders and open a folder/workspace that contains a git repository
  • Make a change to one or more files from the folder/workspace and switch to the "Source Control" viewlet
  • Leave the commit input empty, and click on the "Commit" button
    • Confirm that a new editor with the COMMIT_EDITMSG document gets opened

And issue 153505 "Add a ✅ editor action in COMMIT_EDITMSG and MERGE_MSG"

it's not clear what to do with the commit message editor.
[...] Have an "accept commit message" editor action in the top right as an additional hint here.

https://user-images.githubusercontent.com/2193314/176208127-e945e12e-0727-40da-9f02-e14cc83769d1.png

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
5

For a convenient multiline commit message editor, install an extension called "adam-bender.commit-message-editor".

drjumper
  • 111
  • 1
  • 3
  • Doesn't work correctly with a repo that has sub-repos. Tries to commit the message to a random sub-repo. Or at least the editor gives that impression. – Fizz Dec 21 '21 at 08:55
3

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

Amir_K
  • 31
  • 1
-1

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.

daGo
  • 2,584
  • 26
  • 24