Bille
Bille

Reputation: 401

How do i make Visual Studio Code save changes in files before commit?

I have often made a commit, and then noticed that one of the files i was working on wasn't saved, and therefore were left out of the commit.

I have my current project set up with Husky, and have automated things like testing / linting before commit or push.

Here is the current Husky setup, just to give an idea of where a script could fit in.

 "husky": {
    "hooks": {
      "pre-commit": "pretty-quick --staged && ng lint",
      "pre-push": "ng test --browsers ChromeHeadless --watch=false && testcafe -c 4 chrome:headless test"
    }
  }

Is there any way to make visual studio or Husky save all open files pre-commit?

Upvotes: 3

Views: 4736

Answers (2)

Bille
Bille

Reputation: 401

@Will Taylor's answer inspired me to do some searching. I found the "files.autoSave": "onFocusChange" setting in VSCode, and it solved my problem to a satisfactory degree. Because the file is loosing focus when I write in the terminal, it is saved befor I commit.

Upvotes: 2

Will Taylor
Will Taylor

Reputation: 1759

As far as I know there is no built in option to do this.

However, you have VSCode autosave files as you modify them, by toggling 'autosave' in the 'File' menu. This would solve your problem, but may irritate in other ways (eg. if you if you are developing something with hot reload behaviour).

Upvotes: 1

Related Questions