0

I used to have file named ViewMVC.java that contained declaration of ViewMVC class.

Later, I decided to rename the class to ViewMvc. As a result, file's name changed to ViewMvc.java. I pushed this change into remote a long time ago.

The problem I face is that when I clone remote repo, the file is pulled as ViewMVC.java (the class name is ViewMvc as expected). In other words - for some reason the name of the file gets reverted to a legacy name.

I tried to change the name again and push into remote, but the issue is not resolved this way.

Any ideas why this happens and how could I resolve this annoying issue?

Vasiliy
  • 16,221
  • 11
  • 71
  • 127
  • What OS are you using? I'm wondering if Windows case-insensitive filesystems are playing a role in the chaos... – Mark Adelsberger Mar 27 '17 at 20:00
  • @MarkAdelsberger I'm using a mix. My desktop is Windows, laptop is OSX, and now I'm trying to bring up continuous integration server on centOS. But I tend to believe that the original commit that changed the name of the file was made on Windows... – Vasiliy Mar 27 '17 at 20:04
  • Both Windows and OSX use case-insensitive matching by default, so that `MVC` and `Mvc` are the *same file*. Git has a configuration knob, `core.ignoreCase`, to tell it whether to believe those are the *same file* or *different files*. Simply tweaking the knob is not quite sufficient as Git's use of the knob is to sense how the OS will handle it, and you need *both* Git *and* the OS to be case-sensitive (as CentOS is) here. As for the best way to fix it, well, I avoid Windows; I could test on OSX but have not, so do not know. – torek Mar 27 '17 at 20:12
  • https://stackoverflow.com/questions/10523849/changing-capitalization-of-filenames-in-git https://stackoverflow.com/questions/6899582/i-change-the-capitalization-of-a-directory-and-git-doesnt-seem-to-pick-up-on-it https://stackoverflow.com/questions/26014660/changed-case-of-filename-but-git-wont-forget-the-old-version https://stackoverflow.com/questions/17683458/how-do-i-commit-case-sensitive-only-filename-changes-in-git – Josh Lee Mar 27 '17 at 20:26

2 Answers2

1

Per discussion in the comments, I think the problem is that git didn't actually think you'd changed anything when you renamed the file. You want it to see ViewMVC.java as deleted and ViewMvc.java as a new file (which it will sometimes report as ViewMVC.java renamed to ViewMvc.java), but I'm guessing because of the case-insensitivity settings it just said "nah, nothing changed that matters."

The problem, then, is that the tree object - essentially a text file that reads like a directory listing - has the old capitalization still. Again because of the case insensitivity settings, it will happily address the file using a different capitalization if one exists that way in the work tree; but on clone it defaults to the capitalization in the tree object.

So, you have to get it to update the tree object (ideally in each tip commit that you care about).

On a system with case-sensitive fs (and git config set accordingly) you could simply clone the repo, move the file (again), git add . , use git status to confirm that it sees a rename, and commit.

To fix it on a Windows system, the only thing I can think to try would be to delete the file, commit, then recreate the file with correctly-capitalized filename and commit again.

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52
0

This happens on our project from time to time whenever somebody renames a file which is the same name with a different case.

It's because git is case-insensitive by default, you can change it in settings, but the easiest and quickest solution would be to rename the file to ViewMvc1.java > commit and push > rename again to ViewMvc.java > commit and push.

marmor
  • 27,641
  • 11
  • 107
  • 150