Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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


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'
like image 537
Ian Campbell Avatar asked Apr 07 '15 06:04

Ian Campbell


People also ask

Is git case-sensitive for file names?

The Windows and macOS file systems are case-insensitive (but case-preserving) by default. Most Linux filesystems are case-sensitive. Git was built originally to be the Linux kernel's version control system, so unsurprisingly, it's case-sensitive.

Is git case-sensitive for folder names?

Git is a unix based code. its is case sensitive so it will allow you to have the same name in different cases, and as you except windows will not be tolerated for this. There is nothing you can do about it beside renaming your folders.

Is .gitignore case-sensitive?

Just a note: gitignore is case-sensitive.


2 Answers

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'
like image 95
poke Avatar answered Sep 23 '22 18:09

poke


I found out a very simple solution to this. Say you need to rename a java package "Activities" to "activities". This package contains several files and sub-packages

Follow the sequence of steps

  1. Refactor "Activities" to "ActivitiesTemp" (Shift + F6)
  2. Commit and push these changes
  3. Refactor again from "ActivitiesTemp" to "activities"
  4. Commit and push these changes

Thats All Folks !

like image 44
Sanket Berde Avatar answered Sep 26 '22 18:09

Sanket Berde