lint-staged: what the purpose of 'git add' command

Chris Bao picture Chris Bao · Jan 28, 2019 · Viewed 7.6k times · Source

Recently I started to introduce lint-staged into my Frontend build tool chain. And when I checked the document about it, I always find it works as following:

"husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    },
"lint-staged": {
    "src/**/*.{js,jsx,ts,tsx,json,css}": [
      "prettier --write",
      "eslint --fix src/",
      "tslint --fix --project .",
      "git add"
    ]
  },

and you can find more similar usage in the link: https://github.com/okonet/lint-staged

My confusing point is the last command git add, what's the purpose of that?

My understand is lint-staged only validate the code in staged area after git add and before git commit. So can't understand why we need to add one more git add again.

Answer

Do Async picture Do Async · Jul 21, 2020

You don't need git add since lint-staged 10

From v10.0.0 onwards any new modifications to originally staged files will be automatically added to the commit. If your task previously contained a git add step, please remove this. The automatic behaviour ensures there are less race-conditions, since trying to run multiple git operations at the same time usually results in an error.

Source: https://github.com/okonet/lint-staged#v10