0

I have a very unusual behavior from git. I modified a file that appears twice when I enter my git status command. The name and location of both files is exactly the same. Well it is the same file...

And I try to add them both (with git add fileName or git add .) only one of them is added. Then I tried everything (git restore the one not added, git add the one not added, git restore -- staged the one added - brings me back to initial case - push the one added to add the second one etc.) and nothing seems to work.

Couldn't find anything and the Internet either. Would anyone has any idea why this is happening and how to fix it?

Thanks in advance

Here is the git feedback:

On branch feature/LDS23-18
Your branch is up to date with 'origin/feature/LDS23-18'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   app/Models/SubscriptionHelp.php
    modified:   app/Models/subscriptionHelp.php

Edit :

Even if the names of the files appear to be different on the screen I do have only one file. The one with the lower 's' does not exist

enter image description here

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
Rapkalin
  • 54
  • 5
  • 1
    [Please do not upload images of code/data/errors.](//meta.stackoverflow.com/q/285551) – knittl Feb 08 '23 at 12:00
  • 1
    They are not in double... they have different casings.... so if you are working on _Windows_ (where those filenames are considered the same) and you are changing cases of files... well, expect surprises to pop up. – eftshift0 Feb 08 '23 at 12:00
  • Oh! And what @knittl said is also true. – eftshift0 Feb 08 '23 at 12:01
  • 2
    "subscription" != "Subscription" – knittl Feb 08 '23 at 12:01
  • Thank you all for you anwsers. The subscription with a lower 's' at the beginning doesnt exist in my project :/ And I'm working on Mac – Rapkalin Feb 08 '23 at 12:02
  • The MacOS default file system is weird when it comes to cases: it's case preserving but case insensitive (i.e. it'll let you read a file with the "wrong" case). Git doesn't like that. [Part 1](https://stackoverflow.com/questions/8904327/case-sensitivity-in-git), [Part 2](https://stackoverflow.com/questions/68455900/how-to-deal-with-case-sensitive-files-in-git), [Part 3](https://stackoverflow.com/questions/72082376/case-sensitive-files-and-folders-in-local-git-repository-in-mac) – Joachim Sauer Feb 08 '23 at 12:08
  • Thanks for the warning @knittl I have removed the images from my post – Rapkalin Feb 08 '23 at 12:10
  • 2
    "The subscription with a lower 's' at the beginning doesnt exist in my project" It may not exist in the working tree but perhaps it exists in your most recent commit (and so the index). You need to `git rm` it. – matt Feb 08 '23 at 12:16
  • @matt : Unfortunately I tried and I can't because it removes the file in my project – Rapkalin Feb 08 '23 at 12:22
  • Copy the file elsewhere first. Then do the `git rm`. And then bring it back afterwards. (But it sounds to me like you forgot to say `--cached`.) – matt Feb 08 '23 at 12:23
  • @matt : thanks for your help. I ended fixing the issue but not sure how or why ^^ git rm -f the wrong file a second time and this time the right file stayed in my project so I just commit the change and push – Rapkalin Feb 08 '23 at 13:40

0 Answers0