10

The folder consists of files with filenames like abc~1, 123~1, a1d2~3.

When I do git add --all it says,

$ git add --all
error: Invalid path 'abc~1.png'
error: unable to add abc~1.png to index
fatal: adding files failed

I did a trial and error and I found this error persists only when the tilde symbol is followed by a number.

If the folder is tracked by git for the first time, the other files are also not tracked by Git.

$ git clean --dry-run
Would remove Rest.png
Would remove abc~1.png

Please help how do I fix this issue.

2
  • Are you sure you even want to add all those files with ~ in their names? looks like editor generated temp files to me.. Commented Mar 27, 2015 at 7:33
  • Yes, those images with filenames (abc~1.png) are used in java code. Commented Mar 27, 2015 at 11:27

1 Answer 1

17

This is the result of a change that was made to msys Git in December 2014.

On Windows' default filesystems, FAT and NTFS, DOS-style 8.3 file names are supported for backwards compatibility. That means that there are multiple ways to reference the same file. For example, the file credential-cache--daemon.c can also be accessed via CREDEN~1.C (unless another file has already been mapped to that so-called "short name", i.e. the exact short name is unpredictable).

Since this mapping is unpredictable, we need to disallow such file names on Windows, and while at it, we also exclude other file names incompatible with Windows' file systems (e.g. NUL, CON, etc).

We use the core.protectNTFS guard introduced in the previous commit to make sure that we prevent such file names only when appropriate.

To disable this behaviour, you can run:

git config core.protectNTFS false

However, since the new behaviour is there to protect you, I’d recommend changing it back after having added your files:

git config core.protectNTFS true

Only disable this protection when you need to add files with tildes in the name or check out branches containing such filenames.

In general, I’d recommend avoiding such filenames if working in a Windows environment.

4
  • Thanks a lot Anthony for the link and solution provided. Commented Mar 27, 2015 at 12:31
  • Nice find, +1. Can this be circumvented with a -f flag in git add? Commented Mar 27, 2015 at 12:36
  • 1
    @mu無 No, it can't. Saby, Glad to be able to have helped. I'll bet you won't be the only one affected by this. I've proposed an edit so others can more easily find this question. Commented Mar 27, 2015 at 12:40
  • 1
    thank you for this answer - it helped a lot. windows really has annoying filesystem limitations - my problem was caused by a file with a dot at the end
    – niyou
    Commented Jun 16, 2015 at 10:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.