Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to index file

Tags:

git

I have cloned my repo from github with my running git git version 2.16.2.windows.1.

However, when I want to commit it I get the following error:

error: open("src/hoc/Aux.js"): No such file or directory
error: unable to index file src/hoc/Aux.js
fatal: adding files failed

Below you can find the folder and file content:

enter image description here

Any suggestion what I am doing wrong?

I appreciate your replies!

Update

Please find below what git status gives me:

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .gitignore
        README.md
        config/
        package-lock.json
        package.json
        public/
        scripts/
        src/

nothing added to commit but untracked files present (use "git add" to track)

UPDATE 1

I still get the same error, even when manually adding the src folder:

marcus@Marcus-PC MINGW64 ~/Desktop/Coding Projects/demo-react-burger-builder (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .gitignore
        README.md
        config/
        package-lock.json
        package.json
        public/
        scripts/
        src/

nothing added to commit but untracked files present (use "git add" to track)
like image 799
Carol.Kar Avatar asked Feb 24 '18 07:02

Carol.Kar


People also ask

What is index file in Git?

The Git index is a critical data structure in Git. It serves as the “staging area” between the files you have on your filesystem and your commit history. When you run git add , the files from your working directory are hashed and stored as objects in the index, leading them to be “staged changes”.

What git add does?

The git add command adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit. However, git add doesn't really affect the repository in any significant way—changes are not actually recorded until you run git commit .


1 Answers

A comment of the OP on this answer reveals the cause:

I now removed the aux.js and now everything works fine.

AUX is a special file name in Windows (inherited from the old ages of MS-DOS). It is a special file that denotes a device. While on other OSes (Unix-based) the special device files are located in the /dev directory, MS-DOS (and its successor Windows) recognizes the name in any directory and treats it as a special file. This certainly happens in the Command Prompt (for compatibility with the old MS-DOS programs) but it seems it happens in other contexts too.

The name being special and recognized in any directory, the OS code that handles the file names ignores the provided aux.js file (and its path) and handles aux as the special device file AUX. The character case is not important, on Windows file systems aux and Aux are the same as AUX. Because it thinks it has found a special name, it ignores the file extension.

The same thing happens for NUL, CON, PRN and other special names. Check the complete list here: https://en.wikipedia.org/wiki/Device_file#MS-DOS

There is no solution for this, only workarounds. If you are stuck on Windows or the project is developed on Windows by coworkers, the only way to circumvent this is to avoid these special names. Aux is probably the short of Auxiliary.
Use longer names.


An interesting reading (and the source of wisdom that provided the information I put into this answer) is this article written by Microsoft senior developer Raymond Chen on his blog "The Old New Thing" in 2003.

like image 111
axiac Avatar answered Oct 27 '22 18:10

axiac