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.

Untracked files will be lost if they are in a newly created directory

See original GitHub issue

Description

When I committed portion of the code, some of the untracked files suddenly disappeared. I found that if an entire folder is untracked, the folder will disappear after running lint-staged.

Steps to reproduce

├─staged-a
└─unstaged-folder-b
   └─unstaged-file-c

run lint-staged will lose unstaged-folder-b unstaged-file-c

Debug Logs

expand to view

C:/Users/Kunduin/Documents/GitHub/vue-space/src/components/VsInput/index.tsx will be removed VsInput is a newly untracked folder, index.tsx is a newly untracked file

> lint-staged -d

  lint-staged:bin Running `lint-staged@10.0.0-1` +0ms
  lint-staged Loading config using `cosmiconfig` +0ms
  lint-staged Successfully loaded config from `C:\Users\Kunduin\Documents\GitHub\vue-space\package.json`:
  lint-staged {
  lint-staged   '{stories,src}/**/*.scss': 'stylelint --syntax=scss',
  lint-staged   '{stories,src}/**/*.{ts,tsx,js}': 'prettier --write'
  lint-staged } +6ms
  lint-staged:cfg Validating config +0ms
Running lint-staged with the following config:
{
  '{stories,src}/**/*.scss': 'stylelint --syntax=scss',
  '{stories,src}/**/*.{ts,tsx,js}': 'prettier --write'
}
  lint-staged:run Running all linter scripts +0ms
  lint-staged:git Running git command [ 'rev-parse', '--show-toplevel' ] +0ms
  lint-staged:run Resolved git directory to be `C:/Users/Kunduin/Documents/GitHub/vue-space` +100ms
  lint-staged:git Running git command [ 'diff', '--staged', '--diff-filter=ACMR', '--name-only' ] +89ms
  lint-staged:run Loaded list of staged files in git:
  lint-staged:run [ 'src/components/VsButton/index.tsx' ] +83ms
  lint-staged:gen-tasks Generating linter tasks +0ms
  lint-staged:gen-tasks Generated task:
  lint-staged:gen-tasks {
  lint-staged:gen-tasks   pattern: '{stories,src}/**/*.scss',
  lint-staged:gen-tasks   commands: 'stylelint --syntax=scss',
  lint-staged:gen-tasks   fileList: []
  lint-staged:gen-tasks } +4ms
  lint-staged:gen-tasks Generated task:
  lint-staged:gen-tasks {
  lint-staged:gen-tasks   pattern: '{stories,src}/**/*.{ts,tsx,js}',
  lint-staged:gen-tasks   commands: 'prettier --write',
  lint-staged:gen-tasks   fileList: [
  lint-staged:gen-tasks     'C:/Users/Kunduin/Documents/GitHub/vue-space/src/components/VsButton/index.tsx'
  lint-staged:gen-tasks   ]
  lint-staged:gen-tasks } +2ms
Preparing... [started]
  lint-staged:git Backing up original state... +0ms
  lint-staged:file Trying to access `C:\Users\Kunduin\Documents\GitHub\vue-space\.git\MERGE_HEAD` +0ms
  lint-staged:file Unable to access file `C:\Users\Kunduin\Documents\GitHub\vue-space\.git\MERGE_HEAD` with error: +6ms
  lint-staged:file Error: ENOENT: no such file or directory, access 'C:\Users\Kunduin\Documents\GitHub\vue-space\.git\MERGE_HEAD' +15ms
  lint-staged:git Running git command [ 'ls-files', '--others', '--exclude-standard' ] +120ms
  lint-staged:git Detected untracked files: +104ms
  lint-staged:git .storybook/tsconfig.json
  lint-staged:git src/components/VsInput/index.tsx +1ms
  lint-staged:git Backing up untracked files... +1ms
  lint-staged:file Reading buffer from file `C:/Users/Kunduin/Documents/GitHub/vue-space/.storybook/tsconfig.json` +85ms
  lint-staged:file Reading buffer from file `C:/Users/Kunduin/Documents/GitHub/vue-space/src/components/VsInput/index.tsx` +0ms
  lint-staged:file Done reading buffer from file `C:/Users/Kunduin/Documents/GitHub/vue-space/.storybook/tsconfig.json`! +1ms
  lint-staged:file Done reading buffer from file `C:/Users/Kunduin/Documents/GitHub/vue-space/src/components/VsInput/index.tsx`! +1ms
  lint-staged:git Done backing up untracked files! +4ms
  lint-staged:git Running git command [
  'stash',
  'save',
  '--quiet',
  '--include-untracked',
  'lint-staged automatic backup'
] +87ms
  lint-staged:git Running git command [ 'stash', 'list' ] +286ms
  lint-staged:git Running git command [ 'stash', 'apply', '--index', 'stash@{0}' ] +114ms
  lint-staged:git Running git command [ 'clean', '-df' ] +454ms
  lint-staged:git Running git command [ 'checkout', '.' ] +90ms
  lint-staged:git Running git command [ 'stash', 'list' ] +433ms
  lint-staged:git Running git command [
  'diff',
  '--unified=0',
  '--no-color',
  '--no-ext-diff',
  '--patch',
  'stash@{0}',
  '-R'
] +143ms
  lint-staged:git Done backing up original state! +2s
Preparing... [completed]
Running tasks... [started]
Running tasks for {stories,src}/**/*.scss [started]
Running tasks for {stories,src}/**/*.{ts,tsx,js} [started]
Running tasks for {stories,src}/**/*.scss [skipped]
→ No staged files match {stories,src}/**/*.scss
  lint-staged:make-cmd-tasks Creating listr tasks for commands 'prettier --write' +0ms
  lint-staged:task cmd: prettier --write C:/Users/Kunduin/Documents/GitHub/vue-space/src/components/VsButton/index.tsx +0ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +1ms
prettier --write [started]
prettier --write [completed]
Running tasks for {stories,src}/**/*.{ts,tsx,js} [completed]
Running tasks... [completed]
Applying modifications... [started]
  lint-staged:git Running git command [ 'ls-files', '--modified' ] +636ms
  lint-staged:git Restoring unstaged changes... +703ms
  lint-staged:git Running git command [ 'apply', '-v', '--whitespace=nowarn', '--recount', '--unidiff-zero' ] +181ms
  lint-staged:git Done restoring unstaged changes! +179ms
  lint-staged:git Restoring untracked files... +2ms
  lint-staged:file Writing buffer to file `C:/Users/Kunduin/Documents/GitHub/vue-space/.storybook/tsconfig.json` +3s
  lint-staged:file Writing buffer to file `C:/Users/Kunduin/Documents/GitHub/vue-space/src/components/VsInput/index.tsx` +1ms
  lint-staged:file Done writing buffer to file `C:/Users/Kunduin/Documents/GitHub/vue-space/src/components/VsInput/index.tsx`! +3ms
  lint-staged:file Done writing buffer to file `C:/Users/Kunduin/Documents/GitHub/vue-space/.storybook/tsconfig.json`! +1ms
  lint-staged:git Done restoring untracked files! +5ms
Applying modifications... [completed]
Cleaning up... [started]
  lint-staged:git Dropping backup stash... +1ms
  lint-staged:git Running git command [ 'stash', 'list' ] +187ms
  lint-staged:git Running git command [ 'stash', 'drop', '--quiet', 'stash@{0}' ] +155ms
  lint-staged:git Done dropping backup stash! +407ms
Cleaning up... [completed]
  lint-staged tasks were executed successfully! +3s

Environment

  • OS: Win 10
  • Node.js: v13.0.1-x64
  • lint-staged: v10.0.0-1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
kent426commented, Nov 14, 2019

just ran into this and after the version update, can confirm you that it is fixed now.

1reaction
iirojcommented, Oct 29, 2019

I think I fixed this in https://github.com/okonet/lint-staged/pull/663/commits/ad168dcd5071d7278e5c4e9d17810b6f988f6e10. @Kunduin can you, just in case, also tell us your git version? It might have some different behaviour.

Read more comments on GitHub >

github_iconTop Results From Across the Web

git - Untracked file has disappeared from local directory
A file you're working with while using Git is said to be tracked if and only if that file is currently in Git's...
Read more >
Will I lose Untracked Files when changing git branches?
You have created some new files in your git repository, some have been checked in (using git add) and some are untracked.
Read more >
How to git clean untracked files example
If a developer wants to remove untracked files from a git working tree, the easiest way to do it is with the 'git...
Read more >
How to remove untracked files in git
To remove untracked files, use the git clean command. Let's say we have one new file ( file1.txt ) and one new folder...
Read more >
git pull untracked files - You.com | The Search Engine ...
To remove untracked files / directories do: git clean -fdx. -f - force. -d - directories too. -x - remove ignored files 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