-1

I faced weird behaviour of Git - it does not want to add certain files to repository!

Example:

git add "build-tools\build\config\r2010a\build-all.ini" "build-tools\build\config\r2011a\build-all.ini"
git status -uno

It shows - no files added! (I tried with double quotes around filenames and without - nothing changed, files are exists, checked with "type %file%" command - it correctly shows file content)

But when I do this:

git add "build-tools\build\config\r2010a\build-all.ini" 
git add "build-tools\build\config\r2011a\build-all.ini"
git status -uno

It shows that these 2 files were added correctly.

Ok... I re-created the same folder & files structure, initialized new Git repository and tried the same case - problem is easily reproducible.

So, when adding 2 (or more) of such files it does not add anything at all!

Then I changed example to more simple:

git reset
git add sub1\aaa.txt sub2\bbb.txt
git status

It works fine.

Changed test case to make it more similar to original case:

git reset
git add build-tools\folder-1\sub1\build-ccc.ini build-tools\folder-1\sub2\build-ddd.ini
git status

That also works fine...

So, this command silently does not work:

git add "build-tools\build\config\r2010a\build-all.ini" "build-tools\build\config\r2011a\build-all.ini"

But very similar command works fine:

git add build-tools\folder-1\sub1\build-ccc.ini build-tools\folder-1\sub2\build-ddd.ini

Note: I also tried with other slash char and with duplicated slash - these also does not work:

git add "build-tools/build/config/r2010a/build-all.ini" "build-tools/build/config/r2011a/build-all.ini"
git add "build-tools\\build\\config\\r2010a\\build-all.ini" "build-tools\\build\\config\\r2011a\\build-all.ini"

But why??!!

I cannot find anything in documentation about such limitations for "git add".

Even if there is such limitation - that might be ok. BUT(!) there MUST BE AN ERROR MESSAGE that not all of specified files were added!!! Because currently it is silently ignoring my commands and does not add anything! So, I cannot predict cases when files might be not added to repository! :-(

Questions are:

  1. What exactly is wrong in this particular case? Is it possible to predict/diagnose such 'silent Git failures'?
  2. How to make it working with adding multiple files?
  3. How to make it report an error in case when "git add" fail to add some files?

Thank you.

PS. It is Windows 10 20H2 OS. git version 2.33.0.windows.2 (the latest one for the moment)

PPS. I'm doing migration from MKS to Git and such cases when Git silently does nothing are very dangerous because some changes might be lost during migration which is very bad!

PPPS. I was asked to show shell output, so here it is:

E:\sbx\mks\test1>git add "build-tools/build/config/r2010a/build-all.ini" "build-tools/build/config/r2011a/build-all.ini"

E:\sbx\mks\test1>git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        StkOverflow-GitWeird-fail to add.txt
        build-tools/
        sub1/
        sub2/

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

E:\sbx\mks\test1>git reset

E:\sbx\mks\test1>git add build-tools\folder-1\config\r2010a\build-all.ini build-tools\folder-1\config\r2011a\build-all.ini

E:\sbx\mks\test1>git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
    new file:   build-tools/folder-1/config/r2010a/build-all.ini
    new file:   build-tools/folder-1/config/r2011a/build-all.ini

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        StkOverflow-GitWeird-fail to add.txt
        build-tools/build/
        sub1/
        sub2/

E:\sbx\mks\test1>git reset

E:\sbx\mks\test1>git add "build-tools/build/config/r2010a/build-all.ini" "build-tools/build/config/r2011a/build-all.ini" --verbose

E:\sbx\mks\test1>git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        StkOverflow-GitWeird-fail to add.txt
        build-tools/
        sub1/
        sub2/

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

E:\sbx\mks\test1>

E:\sbx\mks\test1>dir "build-tools\build\config\r2010b\build-all.ini" "build-tools\build\config\r2011a\build-all.ini"
 Volume in drive E is VM_STOR
 Volume Serial Number is xxxx-xxxx

 Directory of E:\sbx\mks\test1\build-tools\build\config\r2010b

2021-09-07  09:08            12 087 build-all.ini
               1 File(s)         12 087 bytes

 Directory of E:\sbx\mks\test1\build-tools\build\config\r2011a

2021-09-07  12:32                11 build-all.ini
               1 File(s)             11 bytes
               0 Dir(s)  150 320 095 232 bytes free

It seems I found a reason of this problem:

E:\sbx\mks\test1>git add build-tools\build\config\R2010A\build-all.ini build-tools\build\config\R2011A\build-all.ini --verbose
add 'build-tools/build/config/R2010A/build-all.ini'
add 'build-tools/build/config/R2011A/build-all.ini'

E:\sbx\mks\test1>git reset

E:\sbx\mks\test1>git add build-tools\build\config\r2010a\build-all.ini build-tools\build\config\r2011a\build-all.ini --verbose

So, filenames are case-sensitive, while windows itself is not case-sensitive... So, "r2010a" and "R2010A" are different folder names. :-\

However, it is still unclear - WHY IT DOES NOT REPORT ANY ERRORS?!

So, for sure - THIS IS BUG IN GIT for Windows!!!

dmitry_bond
  • 378
  • 1
  • 3
  • 15
  • Have you tried escaping "\"? Like `"build-tools\\build\\config\\r2010a\\build-all.ini"` – Justinas Sep 07 '21 at 09:50
  • Ya. I just tried both - "build-tools\\build\\config\\r2010a\\build-all.ini" and "build-tools/build/config/r2010a/build-all.ini" - no way. It also does not work. – dmitry_bond Sep 07 '21 at 09:55
  • 1
    It'd be helpful to not say `It shows - x` `It works fine.` etc. and just show the command prompt, the commands and their output. The only circumstance I'm aware of where `git add` shows no output - is where the files are already tracked. Are they already tracked? Showing the output of `git status` before and after a command would also be helpful. – AD7six Sep 07 '21 at 10:04
  • Of course files are not tracked! I mentioned that I created completely new empty git repository, re-created the same folder & files structure and tried all my commands. – dmitry_bond Sep 07 '21 at 10:07
  • 2
    please calm down and clearly demonstrate that. There is nothing in the question creating a new git repo ("I did x" does not give enough information to know what you actually did). – AD7six Sep 07 '21 at 10:07
  • Can you try `git add --verbose` or `git add --dry-run`? – Daniel Trugman Sep 07 '21 at 10:09
  • Can you `dir` the specific directories and make sure the files are actually there? – Daniel Trugman Sep 07 '21 at 10:09
  • I just added cmdline output to the end of my question. – dmitry_bond Sep 07 '21 at 10:12
  • --verbose and --dry-run does not add anything to console output! I just added shell output to the end of my question. – dmitry_bond Sep 07 '21 at 10:13
  • You don't have a git alias getting in the way, by any chance? – alexis Sep 07 '21 at 10:14
  • Also I just added dir ... output to the end of my question - so you can see that files are exists. I think I do not have any alises, because git was installed only 3 month ago and I not configured anything with aliases. – dmitry_bond Sep 07 '21 at 10:19
  • 1
    Re PPPS That's much more helpful - note that 'edit' does not mean 'append to' - you're going to run out of Peas :). Optimise your question for first readers. Further thoughts: are there git ignore files present (despite the now-deleted answer, `git check-ignore -vvv path` may yield some info), are the `git add` commands actually failing (am not familiar with windows [a reference](https://stackoverflow.com/q/334879/761202)). – AD7six Sep 07 '21 at 10:19
  • @AD7six - you can see that I created new git repository and there are no any ignores. Also I never configured any to be ignored for git. "git check-ignore -vvv ." returns empty output. – dmitry_bond Sep 07 '21 at 10:21
  • In your shell output, you added the test files (when the add succeeded) using forward slashes, whereas you tried adding the actual files using back slashes. Are you sure you tried all possible permutations? – Daniel Trugman Sep 07 '21 at 10:24
  • Any of slashed works fine for git. You can easily check that by repeating the same test case on your side. And - yes, of course I tried all possible slashed. Just not posted them here to save the space. – dmitry_bond Sep 07 '21 at 10:29
  • It seems I found a problem. See last shell output I added to my question. So, git expect case-sensitive filenames, Windows OS reports for it "file exists" but internally GIT is not able to find it. That is why git silently ignores it and not report any errors - because of case-factor for filenames. – dmitry_bond Sep 07 '21 at 10:40
  • 3
    As AD7six says, please can you [edit] your question to incorporate the edits fully, rather than as a long series of postscripts - right now, it's really hard to follow. From your self-answer, it sounds like you have finally been able to reproduce the problem reliably enough to give a [mcve], so if you re-focussed the question on that someone might be able to give more insight on whether this is indeed a bug, and what workarounds might be available. – IMSoP Sep 07 '21 at 12:47
  • I'm ok to re-phrase the question but I still do not understand - how exactly? – dmitry_bond Sep 07 '21 at 12:51
  • 2
    Now that you have something close to a [mcve], you might try setting up a test repository with just a few files and folders that displays the problem, and then make that repository generally available (or provide a series of commands to reproduce it) and send that to the Git-for-Windows folks. – torek Sep 07 '21 at 17:23

1 Answers1

0

So, it looks like there is bug in GIT for Windows - it is incorrectly handle case-sensitive/case-insensitive filenames.

It seems "git add" works differently depending if I'm adding 1 file or multiple files.

When I'm adding 1 file - it is able to correctly recognize that some of folders in a path might be written with different case letters (ex: "r2010a" instead of "R2010A"). In such case it works fine, file is added.

But when I'm adding multiple files by one "git add" command then git became blind and cannot recognize such files/pathes anymore. Also it does not report any errors.

So, effect is - "git add" silently do nothing and not provide any diagnostic on that.

Also I tried to run my test case with "git config --local core.ignorecase false" and with "git config --local core.ignorecase true" - nothing changed, problem still persists.

Here is shell output showing the problem:

E:\sbx\mks\test1>git add "build-tools\build\config\r2010a\build-all.ini" "build-tools\build\config\r2011a\build-all.ini" --verbose

E:\sbx\mks\test1>git add "build-tools\build\config\r2010a\build-all.ini" "build-tools\build\config\R2011A\build-all.ini" --verbose
add 'build-tools/build/config/R2011A/build-all.ini'

E:\sbx\mks\test1>git add "build-tools\build\config\R2010A\build-all.ini" "build-tools\build\config\R2011A\build-all.ini" --verbose
add 'build-tools/build/config/R2010A/build-all.ini'

E:\sbx\mks\test1>git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   build-tools/build/config/R2010A/build-all.ini
        new file:   build-tools/build/config/R2011A/build-all.ini

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

So, as you can see - 1st command was not reported that any files added, also not reported an error.

2nd command reported "add 'build-tools/build/config/R2011A/build-all.ini'" - because only this path match characters case.

3rd command reported "add 'build-tools/build/config/R2010A/build-all.ini'" - because now it also match characters case.

Note: finally I solved this problem by special algorithm which discover actual directory names in a path and always using correct char case in all file pathes. In such case "git add" for multiple files works fine.

dmitry_bond
  • 378
  • 1
  • 3
  • 15