Avoid empty commits?
See original GitHub issueMaybe it’s an edge case but I tested lint-staged on an example where I just mis-formatted a file to see if calling eslint --fix
would do the right thing. It did – the formatting error was corrected – but it also created an empty commit. This is a different behavior compared to a scenario where I would run eslint --fix
manually and then attempted to commit – Git would just tell me “no changes added to commit”.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:9
- Comments:12 (2 by maintainers)
Top Results From Across the Web
Remove empty commits in git - Stack Overflow
One simple (but slow) way to do this is with git filter-branch and --prune-empty . With no other filters, no other commits will...
Read more >Do not remove empty commits during rebase - YouTrack
I create commit via. git commit --allow-empty -m "Shared Indexes Review 8". C detected. Do Push in IDEA. It does rebase. My commit...
Read more >Remove empty commits quickly : r/git - Reddit
I have a project with about 1700 commits and I want to remove all of the empty commits. Are there any ways to...
Read more >How to remove empty commits in Git - DevCoops
Step 1. Once you've created an empty commit (if not, run git commit --allow-empty -m "Test empty commit" ), ...
Read more >git commit --allow-empty - Thread · house
The choice to prevent users from making empty commits makes sense to me as a dummy-proofing and safety-net for people who are too...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If you’re testing the
eslint --fix
command, by just adding some empty lines, producing auto fixable errors that don’t indeed add changes to the codebase, then it makes sense to be an empty commit.By doing so, the “changes” of the commit would be fixed when running
lint-staged
and then, wouldn’t be any changes added to the commit.That’s the reason to have another step after running the tasks - check if it’s a valid commit.
I had the same problem.
This happened to me when I tried the
lint-staged
scripts after filling the file with linting problems (I just added some spaces)And
lint-staged
will fix the linting errors, leaving you with no modifications in the file. This will cause the following error message:Try missing some linting errors and making a modification, such as a
console.log
, and everything should work properly as you expected.