BiscuitBoy
BiscuitBoy

Reputation: 531

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.

Any help would be highly appreciated.

Upvotes: 36

Views: 12333

Answers (3)

VonC
VonC

Reputation: 1324397

VSCode 1.51 (Oct. 2020) does have a similar feature: Alt+Arrow Up:


VSCode 1.81, Aug. 2023, still-dreaming-1 mentions in the comments that:

Now, you don't even need to use the Alt key, just the Arrow Up.
If the cursor is at the start of the box, which it will be initially since it is blank, you can just press the up arrow.


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.

Upvotes: 52

kwood
kwood

Reputation: 10954

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.

Upvotes: 20

Jon
Jon

Reputation: 2128

there's an extension that might be interesting for some people:

https://marketplace.visualstudio.com/items?itemName=JanBn.git-last-commit-message

I've just installed it before knowing about @kwood's answer, given that it helped me for a bit , I'm leaving this as a secondary option.

Upvotes: 6

Related Questions