0

i have a sass file in my repo for example _subfile.scss when i git add <path to the file> the file name is changed to something like this _subFile.scss and i can't see anything related to the old name, if try and add it again it reverts back its name and keeps doing that and i have no idea WHY...

notice tho that i never really made changes to that file AT ALL, it just appeared to me in the modified files list so normally i just stashed it but stashing doesn't do anything to it as well it just stays there...

So any idea why this might be happening and how to solve it ?

Thank you in advance.

EDIT 1: Git status:

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:   src/scss/components/_featureddiscussionsmodule.scss

Git stash:

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:   src/scss/components/_featuredDiscussionsModule.scss

i don't want to add this file because it was never changed at all and i have no idea why its visible in the changes :/

Ali Hassan
  • 198
  • 1
  • 11

1 Answers1

1

You mention that you are using MacOS. MacOS by default has case-insensitive file systems. That is, if you first create a file named, say, ReadMe.txt, then try to create a new and different file named README.TXT, the OS refuses to do what you asked. Instead, it just overwrites your ReadMe.txt file.

Now, in your several git status outputs, we have these two lines:

   modified:   src/scss/components/_featureddiscussionsmodule.scss
   modified:   src/scss/components/_featuredDiscussionsModule.scss

Note the two different file names.

In commits as stored by Git, files are stored in a special, read-only, Git-only, compressed format. They're not ordinary OS files. They do not have file names at the OS level.1 So Git can store two completely different files, one named src/scss/components/_featuredDiscussionsModule.scss and a different one with the all-lowercase name.

Your MacOS file system simply cannot store both files. This means that when you have Git extract this commit to your work-tree, so that you can see and work with the files, one of the files overwrites the other.

You can easily:

  • ignore this situation entirely (just never use or modify this file and allow it to apparently-randomly flip back and forth), or
  • remove one of the two files that winds up with the same name when you work with this commit and then make a new commit, or
  • create a case-sensitive file system: see my answer to How do I change case of the names of multiple files, already committed?

The last method is probably the best, since it allows you to work with colleagues probably using Linux, who probably created this situation in the first place.

(At the same time, you probably want to let them—the colleagues who set this up in the first place—know that they have made a situation where this repository cannot be used correctly on a default MacOS or Windows setup, where the file system is case-insensitive and therefore cannot extract both files.)


1Git uses a form of object store, in which each object's data are stored under hash IDs. The commit itself has a hash ID, and that commit's data include the hash ID of a tree object. Tree data encode file names—as data, not as OS names—and each file's content is stored under yet another hash ID. So all the OS sees are hash ID names, and even that only happens with loose objects: objects eventually get packed, to compress them even further, after which there is only a single packed-objects file, at the OS's file level.

torek
  • 448,244
  • 59
  • 642
  • 775