Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Visual Studio Code remember previous commit messages?

I have recently started using Microsoft's open-source Visual Studio Code IDE for developing web projects, shifting from Eclipse. I find VSCode highly intuitive and very simple to use.

But one feature I miss in VSCode is that the IDE's inability to remember commit messages (or have I not explored enough?!). Unlike Eclipse, which populates a dropdown list of historical commit messages, we have to manually enter commit messages in VSCode every time we commit our changes.

  • Is there any VSCode extension available for this purpose?

  • Can I make any entry in settings.json so that older commit messages are retrieved automatically?

Any help would be highly appreciated.

like image 550
BiscuitBoy Avatar asked Sep 12 '16 07:09

BiscuitBoy


2 Answers

VSCode 1.51 (Oct. 2020) does have a similar feature:

Source Control input box saves commit message history

This addresses a feature request to navigate SCM commit history.

Press kb(scm.viewPreviousCommit) and kb(scm.viewNextCommit) to display the prior and next commits, respectively.
To move directly to the first and last position of the input box, press Alt in conjunction with the corresponding arrow key.

Build off of past commit messages and look back in the history without losing your drafted message.

After typing a message in the SCM input box, then staging and committing changes, pressing the up arrow reveals the message that was just committed.

like image 102
VonC Avatar answered Sep 29 '22 12:09

VonC


No need for a separate extension or something like that. Git can handle this via commit templates and VSCode supports them already.

For example, assuming you have a unix-like and are in the root of your repository:

echo "My fancy commit message" > .mycommitmsg.txt
git config --local commit.template .mycommitmsg.txt

From there, VSC will automatically use the content of .mycommitmsg.txt.

Second step is to fill this message file with the content of your last commit. That can be achieved with Git hooks, in your case you want the post-commit hook.

Create/edit the file .git/hooks/post-commit with the following content:

#!/bin/sh

printf "`git log -1 --pretty=%s`" > .gitmessage.txt

Don't forget to make it executable:

chmod +x .git/hooks/post-commit

From there, everything should work as you described. The post-commit hook will automatically fill the message file with the content of your last message and VSC uses the new message as soon as you commit.

like image 42
kwood Avatar answered Sep 29 '22 13:09

kwood