Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot add to repository

Tags:

git

github

gitlab

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?

like image 827
The Rock Avatar asked Sep 06 '25 00:09

The Rock


2 Answers

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.

like image 169
Duke Avatar answered Sep 07 '25 19:09

Duke


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.

like image 30
torek Avatar answered Sep 07 '25 21:09

torek