After pushing my code to the remote branch and creating a PR. I wanted to make some more changes to my code and then commit to the remote branch again
First, I started these steps:
git add .
git commit -m "Remove semicolons, change to multi line returns"`
But then this appeared right after the commit:

I checked the status and unstage all the added files
git status
git restore --stage .
-> Then I add and commit again, the error is still there.
After that, I undo the commits & pull the branch to start again
git reset HEAD^
git pull
When I'm done making changes to the code, I ran git diff to see the changes I've made.
Finally, I ran git add . & git commit -m "Recommit message", but somehow the error came back
Can anyone help me with what actually happened and how can I fix it?
If we can't fix it, is there any way to revert the code to normal?
Thank you!
Look at the husky line on your screenshot, you have a pre-commit hook running here.
The reason it fires would have to be found in the hook itself, but it looks like the linting process deems that you changed only whitespace (check it with git diff --staged just before committing).
So if you do want to commit only your whitespace changes but the hook prevents it, check .git/hooks/pre-commit and consider using -n for your commit command (--no-verify) to commit without triggering the hook.
The alternative would be to use --allow-empty as hinted in yellow, but without knowing exactly what's in your lint hook, hard to say for sure. Who set up your repo/workflow? That hook has likely been put here for a reason, so be sure to discuss the matter with them.
I found a good explanation of the problem in this article. At the end of the article it says the following:
lint-stage error out saying it was an empty git commit - a commit with no changes. No changes because all the changes I made were formatting changes, which were wrong according to prettier and it fixed it back and on doing so, there was no changes left to even be committed to git.
I think that the situation is similar with the processing of eslint files. Write code that does not contradict the rules of eslint and prettier and this error will not occur.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With