Git case-sensitivity error -- renaming and committing from Android Studio

Ian Campbell picture Ian Campbell · Apr 7, 2015 · Viewed 11.9k times · Source


For example, I have a file named FOOBar.java that I want to rename to FooBar.java. After trying lots of stuff, I get the error:

enter image description here

Error:error: pathspec 'app/src/main/java/blahblah/FooBar.java' did not match any file(s) known to git.


Things I have tried (not working, all produce the same error):

from Android Studio:

  • deleting FOOBar.java, re-creating FooBar.java, adding/committing with Git
  • refactoring/renaming the file, adding/committing with Git
  • File --> Invalidate Caches / Restart..., then trying one of the above
  • Rebuild Project before/after any of the above

in the file system:

  • deleting the .gradle folder in the project folder, then trying one of the above in Android Studio

from the Git command line:

  • git mv FOOBar.java FooBar.java --force then git commit FooBar.java -m 'renamed from FOOBar.java to FooBar.java'

Answer

poke picture poke · Apr 7, 2015

Windows’ file system is mostly case-insensitive, so you cannot rename a file by just changing its capitalization. Instead, you will have to use a temporary name in between.

Try the following from the command line:

git mv FOOBar.java FooBar.java.new
git mv FooBar.java.new FooBar.java
git commit -m 'Rename file'