Home > Mobile >  How do I solve this empty git commit warning?
How do I solve this empty git commit warning?

Time:03-14

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: enter image description here

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!

CodePudding user response:

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.

  • Related