Using git add inside pre-commit hook
TL; DR: Using eslint --fix
&& & git add
in pre-commit mode, but it leaves staged and unstaged files! Using post-commit bindings git reset <staged-files>
seems to work, but is there a solution for this?
To give some background, I started using lint-staged
and husky
to automatically fix JavaScript lint errors on git commit
. This works very well if you commit your changes first and then commit, for example:
git add index.js
git commit -m "Some Message"
IntelliJ IDEA seems to commit files directly (for example git commit -m "Some Message" index.js
) that are still working, files are automatically committed. Unfortunately it also leaves a staged file (auto-fixed) and an unset file (original lint errors) and this is the problem I want to resolve.
Not knowing where to start, I opened the question 151 with , but after some investigation of the problem seems to be associated with the Git, instead . lint-staged
lint-staged
I only have basic Git skills, so to minimize distractions I created the project without lint-staged
or husky
and manually added a pre-commit hook. Then I ran the same tests (for example git commit -m "Some Message" index.js
) and no wonder the same problem occurred. In an attempt to solve the problem, I also added a post-commit hook that launches git reset <staged-files>
, which seems to work well, but I'm not sure if this is the right solution.
If you have experience with this or are a Git Guru take a look at the demo repo and let us know if there is a better way. Any help would be greatly appreciated.
source to share
No one has answered this question yet
Check out similar questions: