Git add -A usage

Viewed 64

I am using Husky in my ReactJs project. The idea is when user will commit the changes there should be run some lint commands.For this i added in my package.json:

    "lint": "next lint --fix",
    "lint:fix": "lint && git add -A .",

Before committing the message i run lint:fix. Everything is working.
Also i know that this command git add -A . will add the changes if they will occur after lint command, so if the dev will commit => lint will fix the issues => and if there are some changes git automatically will add these changes to the commit without doing again git add . and git commit -m ....
Question: Have this command git add -A . any disadvantages and is it ok to add there?

1 Answers

Have this command git add -A . any disadvantages

First git add . is enough (the -A is the default since Git 2.x)

Second, the main (in general) inconvenient is that it adds everything, even if you might have other unrelated modifications. It also adds new files.

In your case (used in a pre-commit hook), you have prepared your index (git add only the files you want to commit): the git add . might risk adding other files that you did not want initially to iclude in your next commit.


another question, is lint-staged (https://npmjs.com/package/lint-staged) the same as git add -u in my situation "lint:fix": "lint && git add -u"?

The README mentions:

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.

Related