question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Avoid empty commits?

See original GitHub issue

Maybe 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:closed
  • Created 5 years ago
  • Reactions:9
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

17reactions
LauraBeatriscommented, Nov 23, 2020

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.

image

5reactions
YoussefZidancommented, Mar 16, 2022

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)

  "lint-staged": {
    "**/*.{js,jsx}": [
      "yarn eslint --fix",
      "prettier  --write"
    ]
  }

And lint-staged will fix the linting errors, leaving you with no modifications in the file. This will cause the following error message:

⚠ lint-staged prevented an empty git commit.
  Use the --allow-empty option to continue, or check your task configuration

Try missing some linting errors and making a modification, such as a console.log, and everything should work properly as you expected.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found