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.

error: could not restore untracked files from stash

See original GitHub issue

Description

This error happens when I run lint-staged v10 with untracked files in my working directory, and the linter fails. When this occurs, lint-staged leaves all my working changes in the stash (OK, they are safe), but manually restoring the stash is not easily possible (git complains about overwriting the untracked files).

Steps to reproduce

For a minimal reproduction, we need a fresh git repo:

mkdir test-lint && cd test-lint
git init
echo '{}' > package.json
echo '{ "*.js": "false" }' > .lintstagedrc
echo 'node_modules' > .gitignore
yarn add --dev lint-staged
git add .
git commit -a -m "Initial commit"

Now we can trigger the problem:

  • Create foo.js & git add foo.js
  • Create bar.js but don’t stage it.
  • Run lint-staged:
✔ Preparing...
  ❯ Running tasks...
    ❯ Running tasks for *.js
      ✖ false
  ↓ Applying modifications... [skipped]
    → Skipped because of errors from tasks.
  ✖ Reverting to original state because of errors...
    → error: could not restore untracked files from stash
  ↓ Cleaning up... [skipped]
    → Skipped because of previous 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}: On master: automatic lint-staged backup
    > git stash pop stash@{0}

Now even git stash pop won’t work:

bar.js already exists, no checkout
error: could not restore untracked files from stash
The stash entry is kept in case you need it again.

Debug Logs

expand to view
  lint-staged:bin Running `lint-staged@10.1.1` +0ms
  lint-staged:bin Options parsed from command-line: {
  allowEmpty: false,
  concurrent: true,
  configPath: undefined,
  debug: true,
  maxArgLength: 131072,
  stash: true,
  quiet: false,
  relative: false,
  shell: false
} +1ms
  lint-staged Loading config using `cosmiconfig` +0ms
  lint-staged Successfully loaded config from `/Users/william/airbitz/tmp/test-lint/.lintstagedrc`:
  lint-staged { '*.js': 'false' } +42ms
  lint-staged:cfg Validating config +0ms
Running lint-staged with the following config:
{
  '*.js': 'false'
}
  lint-staged Unset GIT_LITERAL_PATHSPECS (was `undefined`) +2ms
  lint-staged:run Running all linter scripts +0ms
  lint-staged:resolveGitRepo Resolving git repo from `/Users/william/airbitz/tmp/test-lint` +0ms
  lint-staged:resolveGitRepo Unset GIT_DIR (was `undefined`) +0ms
  lint-staged:git Running git command [ 'rev-parse', '--show-toplevel' ] +0ms
  lint-staged:resolveGitRepo Resolved git directory to be `/Users/william/airbitz/tmp/test-lint` +12ms
  lint-staged:resolveGitRepo Resolved git config directory to be `/Users/william/airbitz/tmp/test-lint/.git` +0ms
  lint-staged:git Running git command [ 'diff', '--staged', '--diff-filter=ACMR', '--name-only', '-z' ] +12ms
  lint-staged:run Loaded list of staged files in git:
  lint-staged:run [ 'foo.js' ] +20ms
  lint-staged:chunkFiles Resolved an argument string length of 43 characters from 1 files +0ms
  lint-staged:chunkFiles Creating 1 chunks for maxArgLength of 131072 +0ms
  lint-staged:gen-tasks Generating linter tasks +0ms
  lint-staged:gen-tasks Generated task:
  lint-staged:gen-tasks {
  lint-staged:gen-tasks   pattern: '*.js',
  lint-staged:gen-tasks   commands: 'false',
  lint-staged:gen-tasks   fileList: [ '/Users/william/airbitz/tmp/test-lint/foo.js' ]
  lint-staged:gen-tasks } +2ms
  lint-staged:make-cmd-tasks Creating listr tasks for commands 'false' +0ms
  lint-staged:task cmd: false +0ms
  lint-staged:task args: [] +0ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +1ms
Preparing... [started]
  lint-staged:git Backing up original state... +0ms
  lint-staged:git Getting partially staged files... +1ms
  lint-staged:git Running git command [ 'status', '--porcelain' ] +14ms
  lint-staged:git Found partially staged files: [] +13ms
  lint-staged:git Getting deleted files... +0ms
  lint-staged:git Running git command [ 'ls-files', '--deleted' ] +13ms
  lint-staged:git Found deleted files: [] +8ms
  lint-staged:git Backing up merge state... +0ms
  lint-staged:file Reading file `/Users/william/airbitz/tmp/test-lint/.git/MERGE_HEAD` +0ms
  lint-staged:file Reading file `/Users/william/airbitz/tmp/test-lint/.git/MERGE_MODE` +0ms
  lint-staged:file Reading file `/Users/william/airbitz/tmp/test-lint/.git/MERGE_MSG` +1ms
  lint-staged:file File `/Users/william/airbitz/tmp/test-lint/.git/MERGE_HEAD` doesn't exist, ignoring... +0ms
  lint-staged:file File `/Users/william/airbitz/tmp/test-lint/.git/MERGE_MODE` doesn't exist, ignoring... +0ms
  lint-staged:file File `/Users/william/airbitz/tmp/test-lint/.git/MERGE_MSG` doesn't exist, ignoring... +0ms
  lint-staged:git Done backing up merge state! +1ms
  lint-staged:git Running git command [
  'stash',
  'save',
  '--include-untracked',
  'lint-staged automatic backup'
] +9ms
  lint-staged:git Running git command [ 'stash', 'list' ] +42ms
  lint-staged:git Running git command [ 'stash', 'apply', '--quiet', '--index', 'stash@{0}' ] +16ms
  lint-staged:git Restoring merge state... +101ms
  lint-staged:git Done restoring merge state! +0ms
  lint-staged:git Done backing up original state! +0ms
Preparing... [completed]
Running tasks... [started]
Running tasks for *.js [started]
false [started]
false [failed]
→
Running tasks for *.js [failed]
→
Running tasks... [failed]
Applying modifications... [started]
Applying modifications... [skipped]
→ Skipped because of errors from tasks.
Reverting to original state because of errors... [started]
  lint-staged:git Restoring original state... +7ms
  lint-staged:git Running git command [ 'reset', '--hard', 'HEAD' ] +50ms
  lint-staged:git Running git command [ 'stash', 'list' ] +10ms
  lint-staged:git Running git command [ 'stash', 'apply', '--quiet', '--index', 'stash@{0}' ] +16ms
Reverting to original state because of errors... [failed]
→ bar.js already exists, no checkout
error: could not restore untracked files from stash
Cleaning up... [started]
Cleaning up... [skipped]
→ Skipped because of previous 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}: On master: automatic lint-staged backup
    > git stash pop stash@{0}




✖ false found some errors. Please fix them and try committing again.
bar.js already exists, no checkout
error: could not restore untracked files from stash

Environment

  • OS: macOS Catalina
  • Node.js: v13.11.0
  • lint-staged: 10.1.1
  • git version 2.26.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:11

github_iconTop GitHub Comments

1reaction
swansonteccommented, Apr 7, 2020

I have to say, wow! You guys sure solved this thoroughly and quickly. I really appreciate the great piece of software, and now the awesome responsiveness. Thanks a lot!

0reactions
github-actions[bot]commented, Apr 5, 2020

🎉 This issue has been resolved in version 10.1.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does git stash pop say that it could not restore untracked ...
Under the theory that git was unable to merge 2 different new files, I deleted each of the named files in my working...
Read more >
Could not restore untracked files from stash - GitHub Gist
How to fix 'Could not restore untracked files from stash' issue ; Convert a stash to a temporary branch. git stash branch STASHTEMPBRANCH...
Read more >
HELP! "stash pop" is failing and I can't get my work out
At that point I begrudgingly try a 'stash/pull/pop' but that doesn't work either in general due to conflicts with untracked files, so then...
Read more >
Problem with GIT to get files back from stash
Hi folks, I faced problem while getting back files from stash (this includes old files + new files). It works well with old...
Read more >
Could not restore untracked files from stash - Apple Developer
I have three suggestions to help you. The first suggestion is to install Sourcetree, which is a free git app. Sourcetree shows your...
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