4

I have two files that have been renamed from lowercase to uppercase and the most frustrating and out-of-left-field crazy thing happened. Git now sees TWO COPIES, one with the upper case name and one with the lower case name of each file. Let me be clear: no such lower case files exists. Git is literally seeing imaginary files.

In order to commit a change to either of these files, I have to commit "both" the real file and the imaginary file. Attempting to discard one unstaged file will create a removal of the changes in the opposite case, e.g. discarding server.h will create Server.h with reversal of changes, and vice versa, thus deletion is impossible.

  • 2 files
  • initially lowercase (server.h, server.cpp)
  • renamed to uppercase (Server.h, Server.cpp)
  • Git now sees TWO COPIES
    • "git status" output:
      modified: Server.h
      modified: Server.cpp
      modified: server.h <---- (doesn't exist)
      modified: server.cpp <---- (doesn't exist)

The duplicate files server.h and server.cpp, in all lowercase, do not exist, as noted above.

I have attempted changing .git/config to enable case sensitivity, which doesn't change anything. What else could be causing these duplicate, imaginary files?

Edit: as noted above, enabling or disabling case sensitivity settings did not solve the problem, and attempting to remove either file doesn't work.

user0934
  • 126
  • 9

1 Answers1

0

I think this is just a result of some common confusion that occurs when renaming files. Basically, in this case you need to git add both the "removed" (lowercase) and "added" (uppercase) files.

As a test, if you enter git add --all you should get some result like "Renamed: server.h -> Server.h". If this doesn't occur, simply enter git reset HEAD . to get back to how you were before.

Although if you've got more complicated changes than what you indicate in your question, and you're afraid of losing some other modification (s), you might also want to look into the git stash command.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
J.M. Janzen
  • 671
  • 1
  • 8
  • 19
  • 1
    The question isn't how to commit the files, the question is why these phantom files exist in git when they don't exist on the file system. – user0934 Apr 13 '16 at 11:36
  • Just tried your suggestions, and git add did not display "Renamed:...", it displayed what I show in the question, and git reset HEAD did not remove the dual files. I know I have to add both files to make it work, I'm simply asking why the phantom one exists. – user0934 Apr 13 '16 at 11:47
  • My apologies - I misunderstood. That is indeed strange. What happens with you run `git diff` on an 'imaginary' file? How does it compare to the diff of the 'real' file? – J.M. Janzen Apr 13 '16 at 15:13