'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?



Solution 1:[1]

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.

Solution 2:[2]

  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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 torek
Solution 2 evilReiko