lint-staged: lint-staged failed due to a git error
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
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 16
- Comments: 20 (3 by maintainers)
@quadristan You are right, the problem is, that
pnpm -r
will run in concurrency (currently 4 processes); I simply calllint-staged
now withpnpm -r --workspace-concurrency=1 lint-staged
and everything works like a charm!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 runslint-staged
version 11.0.1).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.In the case with submodule,
lintstaged --no-stash
solves this problem. I would thinkprepare
method inlibs/GitWorkflow.js
cannot handle submodule hash correctly.We had this issue at work. We pin-pointed the issue with our pnpm mono-repo structure. By default, it uses parallelism. However, lint-staged do some git operations which cannot be ran concurrently.
tl;dr: if you have a mono-repo, be sure that you are not running multiple times lint-staged concurrently
That was exactly my case and it worked, but I didn’t understand why. Can you elaborate?
If there is a command called
npx lint-staged
in the pre-commit file under the .husky directory, you will see that the error is resolved if you add the following command snippet to the end and then commit:--no-stash
Note: If you are working on a personal project, there is no problem in committing this change you made in the pre-commit file. However, you should be careful when committing to a large-scale, multi-participant or company project. In this case, the only drawback is that it needs to be done before each commit.
@peilingjiang @vmilersky As a temporary workaround, try adding
--no-verify
to lint-staged as stated in https://github.com/okonet/lint-staged/issues/795. Hope that helps!Got this error on my setup with
husky
andnext
The solutions
--no-stash
- 🤷🏻 i don’t understand--concurrent false
- 👍🏻 found in this repo, guess this solves the main problem - intersection of a tasks / filesConfig example
.husky/pre-commit
.husky/pre-push
.lintstagedrc.js
package.json
So to me it now sounds like this issue is about running lint-staged in parallel in a monorepo. This is already mentioned in the readme: run it on the root level only once, and have multiple configs instead.
https://github.com/lint-staged/lint-staged?tab=readme-ov-file#how-to-use-lint-staged-in-a-multi-package-monorepo
Posting a reply like this is not helpful. Without debug logs it’s not possible to tell what the issue is. This issue already has multiple reports of different issues in it.
In my case, opening a new terminal fixed my issue.
Pull requests are welcome if you manage to make it work better with submodules!