The Rock
The Rock

Reputation: 413

Cannot add to repository

Here is error when i use git add .

 $ git add .
    error: short read while indexing .editorconfig
    error: .editorconfig: failed to insert into database
    error: unable to index file '.editorconfig'
    fatal: adding files failed

How can i fix it?

Upvotes: 3

Views: 5039

Answers (4)

softwaretotest
softwaretotest

Reputation: 1

In my case I had this file NUL in my project folder, that could not be moved or deleted or read at all. It is like kind of bug.

When I tried to move the file NUL It showed error like internal failure number 8x????

My solution:

I replicate my project folder without the file NUL

Then the failure with git add . is gone

Upvotes: 0

Duke
Duke

Reputation: 7444

In my case the folder was on a Mac, stored in iCloud & also being backed up via git. The File API sometimes removes files from disk. I opened the folder in Finder and clicked the download button, then it worked.

Upvotes: 3

evilReiko
evilReiko

Reputation: 20473

  1. Find the file causing the problem
  2. Copy-paste the file's content to a temporary file
  3. Revert changes on the problematic file
  4. Run your "git add" command, then
  • If "git add" succeeded, copy-paste content from temporary file to the problematic file, then run your "git add" command again, it should work.
  • If "git add" failed because another file causing same 1-4 problem, repeat steps for the new problematic file.

Upvotes: 0

torek
torek

Reputation: 488453

This (error: short read while indexing name) happens when Git finds a file of the given name, gets information from the OS about that file, and goes to add that file to the index aka staging-area. Git:

  • uses the file's name to open the file;
  • reads the contents of the file; and
  • discovers that although the system said the file was at exactly N1 bytes long, Git was only able to read N0 bytes, where N0 < N1.

On Git-for-Windows when using WSL, there's a new feature whereby you can allow the system to store two files that differ only in the case of some names, e.g., both readme.txt and README.TXT. Normally Windows only allows one such name, and once the name exists, using any variant—including ReAdMe.TxT or reaDME.tXT or whatever—gets you the one file. Git-for-Windows makes too much use of this assumption, which WSL has now broken.

The solution for now is:

  • don't do this, and/or
  • don't use Windows.1

Eventually, the Git-for-Windows folks will build a version of Git-for-Windows that handles the problem.


1The macOS folks may snicker at the Windows folks here, but macOS has similar issues. In some ways the macOS issues can be worse (NFC vs NFD names), though in other ways the Windows issues are worse (can't create files named aux.c and aux.h). Git needs a proper general mechanism here, really, but in some ways this is an unsolvable problem.

Upvotes: 4

Related Questions