VS Code Tip: commit part of a file

A cool feature of Git is that you can stage/commit some of the modifcations that were made to a file while leaving the other parts unstaged.

This is nice when you’ve made several changes and need to commit one of them to fix something asap.

You can use this Git feature right from VS Code. Select the changes you want commited by clicking the change indicators in the gutter.

selectChange

Stage the change using the + icon.

stageChange

You can then commit it normally. You will see your other unstaged changes for this file under the CHANGES header.

commitChange

JavaScript tip: format console.log output

You can format the output of console.log() using CSS. Use %c in your console log string and then add an argument for the CSS.

Here’s a simple script that uses CSS formatting to make a formatted console logger:

const fl = {
  log: function (title, message, color) {
    console.log('%c%s:%c %s', 
      `color: ${color}; font-weight: bold; text-decoration: underline ${color}`,
      'color: black',
      title, message);
  },

  info: function (message) {
    this.log('Info', message, 'green');
  },

  warning: function (message) {
    this.log('Warning', message, 'orange');
  },

  error: function (message) {
    this.log('Error', message, 'red');
  }
};

 

Here is the result in the console:

console formatting