lint-staged failed due to a git error

See original GitHub issue

Description

Unable to commit due to git error while nothing was done except for changing some files.

Steps to reproduce

git commit -m 'msg'

Debug Logs

[STARTED] Preparing… lint-staged:git Backing up original state… +0ms lint-staged:git Getting partially staged files… +0ms lint-staged:git Running git command [ ‘status’, ‘-z’ ] +89ms lint-staged:git Found partially staged files: [] +30ms lint-staged:git Backing up merge state… +0ms lint-staged:file Reading file .../.git/MERGE_HEAD +0ms lint-staged:file Reading file .../.git/MERGE_MODE +0ms lint-staged:file Reading file .../.git/MERGE_MSG +0ms lint-staged:file File .../.git/MERGE_HEAD doesn’t exist, ignoring… +1ms lint-staged:file File .../.git/MERGE_MODE doesn’t exist, ignoring… +0ms lint-staged:file File .../.git/MERGE_MSG doesn’t exist, ignoring… +0ms lint-staged:git Done backing up merge state! +1ms lint-staged:git Getting deleted files… +56ms lint-staged:git Running git command [ ‘ls-files’, ‘–deleted’ ] +87ms lint-staged:git Found deleted files: [] +13ms lint-staged:git Running git command [ ‘stash’, ‘create’ ] +13ms lint-staged:git Running git command [ ‘stash’, ‘store’, ‘–quiet’, ‘–message’, ‘lint-staged automatic backup’, ‘’ ] +19ms [FAILED] Preparing… [STARTED] Running tasks… [SKIPPED] Skipped because of previous git error. [STARTED] Applying modifications… [SKIPPED] [SKIPPED] ✖ lint-staged failed due to a git error. [STARTED] Cleaning up… [SKIPPED] [SKIPPED] ✖ lint-staged failed due to a git error.

✖ lint-staged failed due to a git error. Any lost modifications can be restored from a git stash:

> git stash list
stash@{0}: automatic lint-staged backup
> git stash apply --index stash@{0}
expand to view
COPY THE DEBUG LOGS HERE

Environment

  • OS: macOS Big Sur
  • Node.js: v12.18.2
  • lint-staged: 10.5.1

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:14
  • Comments:9

github_iconTop GitHub Comments

11reactions
vmilerskycommented, Jul 21, 2021

I’m experiencing the same error in monorepo using Lerna to run lint-staged in all workspaces/packages (lint:staged is just a script in package.json that runs lint-staged version 11.0.1).

lerna info Executing command in 2 packages: "yarn run lint:staged"
lerna ERR! yarn run lint:staged exited 1 in 'b2b'
lerna ERR! yarn run lint:staged stdout:
$ lint-staged
[STARTED] Preparing...
[STARTED] Running tasks...
[SKIPPED] Skipped because of previous git error.
[STARTED] Applying modifications...
[SKIPPED]
[SKIPPED]   ✖ lint-staged failed due to a git error.
[STARTED] Cleaning up...
[SKIPPED]
[SKIPPED]   ✖ lint-staged failed due to a git error.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
lerna ERR! yarn run lint:staged stderr:
⚠ Some of your tasks use `git add` command. Please remove it from the config since all modifications made by tasks will be automatically added to the git commit index.

[FAILED] Preparing...

  ✖ lint-staged failed due to a git error.
  Any lost modifications can be restored from a git stash:

    > git stash list
    stash@{0}: automatic lint-staged backup
    > git stash apply --index stash@{0}

error Command failed with exit code 1.
lerna ERR! yarn run lint:staged exited 1 in 'b2b'
lerna WARN complete Waiting for 1 child process to exit. CTRL-C to exit immediately.
husky > pre-commit hook failed (add --no-verify to bypass)

The command yarn workspace b2b lint:staged ran by itself is finished successfully.

I’m bypassing the error above by using --no-verify. However this happens only if there is a huge amount of changes to be committed. When I commit a single change the problem is not there and lint works well.

4reactions
ChristianUlbrichcommented, Aug 10, 2022

@quadristan You are right, the problem is, that pnpm -r will run in concurrency (currently 4 processes); I simply call lint-staged now with pnpm -r --workspace-concurrency=1 lint-staged and everything works like a charm!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix "lint-staged failed due to a git error" - Stack Overflow
Solved this issue. I checked my .git folder and found a lint-staged_unstaged.patch file. I deleted that and resolved the issue.
Read more >
lint-staged - npm
This project contains a script that will run arbitrary shell tasks with a list of staged files as an argument, filtered by a...
Read more >
Fix Your Mistakes, Don't Commit Them! Pre-Commit Git Hook ...
It's time to stop committing broken tests, ugly code, type errors and lint errors to your git repository. With Husky, we can hook...
Read more >
Git提交前代码检查报错:lint-staged failed due to a git error
Git 提交前代码检查报错:lint-staged failed due to a git error. 一方湖泊 已于 2022-09-19 13:24:13 修改 436 收藏. 分类专栏: # Git 文章标签: git github.
Read more >
Linting Staged Git Files with lint-staged -- newline - Fullstack.io
While coding, you may have the linting tool running in watch mode within a terminal to monitor and report errors and warnings whenever...
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