0

Problem: I have personal PhD projects on GitHub that are solely for me (i.e. no pull/branches) and I have been trying to create a keyboard binding (or via any means) that can autofill the current date and time. It would look more professional then my current method of just using t or whatever key so I can see when browsing the repository when things were updated without consulting the history. I would like a key that could do this please:

enter image description here

What I have tried: I have found an answer by @ianyongli to How to insert current date time in vscode? that I have adapted like so:

{
    "key": "ctrl+.",
    "command": "git.commit",
    "args": {
        "snippet": "$CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND"
    }
},

However, this brings up the "please provide a message for Git" and does not work (as it naturally just commits). git.commit had no further options and git. itself had many options I did not understand like git.commitMessageAccept which does not work. The linked answer works in text and I can copy and paste it into the box but wouldn't mind an automatic way.

What am I missing please?

It would be nice but not essential if it committed and pushed at the same time, like I mentioned earlier this is not for professional purposes. I am familiar with programming but not VS code intricacies. I searched on this site for questions concerning inserting text into that message box but couldn't even find what the message box is called internally hence this question.

rioV8
  • 24,506
  • 3
  • 32
  • 49
JamesT
  • 117
  • 1
  • 3
  • 15
  • 1
    where did you get that snippets can be used in this command? Also related if you want to go another route: https://stackoverflow.com/q/4086896/11107541 – starball May 06 '23 at 22:25
  • @user I only recently started using VS code as it is a LOT easier to deal with LaTeX files and has many good features. I was not sure if snippets could be used like that or not but I didn't know I could make a template, thank you for the link! – JamesT May 06 '23 at 22:29

1 Answers1

1

why add the date to the commit message, it is already part of the commit.

modify your log statement with an alias: show the date, in a one line version and the ref names (branches)

git config --global alias.logd 'log --pretty=tformat:"%C(auto)%ci %h%d %s"'

to use it give the command on the terminal

git logd

rioV8
  • 24,506
  • 3
  • 32
  • 49
  • Thank you for your answer, I like the format but I get an error when I run it: `fatal: bad alias.logd string: unclosed quote`, I copy and pasted your code into a terminal then ran `git logd`. Where am I to use this command please? – JamesT May 07 '23 at 08:33
  • @JamesT both commands should be typed in the terminal, have you copied the end `'` also – rioV8 May 07 '23 at 10:29
  • Yeah I am using both, I updated my Git too. This is my terminal output got Git CMD, it does the same in my CMD prompt and VS code terminal, here is it: https://imgur.com/a/KBpHajC – JamesT May 07 '23 at 10:39
  • @JamesT what do you see when you do `git config --global --list` does it show the missing quote, I used git bash for git on windows it will give you argument completion on TAB, don't use cmd – rioV8 May 07 '23 at 10:44
  • When I use git bash, it is showing this for some bizarre reason: `alias.logd='log` when I used `git config --global --list`. It is for some reason not showing the `--pretty=...` part – JamesT May 07 '23 at 10:47
  • @JamesT have you typed the `config` command also in git bash, cmd does not handle `'` properly, maybe after using git bash to set the alias you can use cmd – rioV8 May 07 '23 at 10:49
  • No but now it works, I had to `--replace-all`, it wasn't being overwritten for some reason, works now thank you so much! – JamesT May 07 '23 at 10:51