Backstory: There was one frontend repo(let's call it repo A) in my organization which had casing issues in names of folders, I renamed a folder to confirm it with casing of other folders. During this adventure I noticed that git doesn't support folder rename, I looked up on stackoverflow for help and somehow was able to rename the folder, then commit some changes into the files of that particular folder.
Present:
I cloned repo A and switched to the branch in which I had did my folder-rename adventure. I notice that there are some changes already in staging area, ready to be git add
I did git add
curious that I had already done it before in my commits, I did git status
again and to my shock, the files were still there, I tried git stash
and observed that there was an entry in git stash
but there were still 3 files in staging area, ready to be git add
, I did git stash
again but there were still 3 files.
Note: I just observed that in remote my folder name is metricCharts
but when I clone it in my system folder name stays MetricCharts
and when I git stash
it, I see that folder name in path changes to metricCharts
and then if I try git add
, it is added
My Question is why is this happening?
The default file systems on macOS and Windows are case insensitive on search. They store the file name using the case that you provided but they find metricCharts
both when you search for metricCharts
or MetricCharts
. This fouls Git when a file is renamed and the only difference is in casing.
The solution is very simple and it involves two renames:
git status
must report "nothing to commit, working tree clean").That's all. It works for directories the same way.