问题
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:
![]()
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-creatingFooBar.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
.gradlefolder in the project folder, then trying one of the above in Android Studio
from the Git command line:
git mv FOOBar.java FooBar.java --forcethengit commit FooBar.java -m 'renamed from FOOBar.java to FooBar.java'
回答1:
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'
回答2:
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
- Refactor "Activities" to "ActivitiesTemp" (Shift + F6)
- Commit and push these changes
- Refactor again from "ActivitiesTemp" to "activities"
- Commit and push these changes
Thats All Folks !
回答3:
I had a similar problem and i fixed it changing git config:
git config core.ignorecase false
回答4:
Rename the file back to the original one, then rename it to a different name, then back to the one with the correct capitalization. Git will not throw the bug anymore, it's the same solution as Poke pointed out, but using android studio.
Example:
Created FOOBar class.
Renamed it to FooBar and then got the error.
Rename it back to FOOBar.
Rename to FooBarTest.
Rename to FooBar.
Git works now.
回答5:
I also faced the almost same situation, in my case I have created a file and added to git (using git add ), after adding to git I have renamed the file. While committing I got the same type error. I solved with the following step
use git status to see the staged files you can see your old file in the list
-
-
app/src/main/java/blahblah/FOOBar.java
-
-
use git reset to remove file from staging
git reset app/src/main/java/blahblah/FOOBar.java
After removing from staging you can add your new file
git add app/src/main/java/blahblah/FooBar.java
after this you can commit
回答6:
A really simple fix I found was to do this command in terminal
git reset
回答7:
Try to restart the Android Studio!
I had this problem on a repository with no commits.
回答8:
http://binaryjeremys.blogspot.com/2015/03/android-studio-doesnt-like-it-when-you.html
To fix this issue, I had to reset to head with the steps below:
Backup the files first: Right-click one of the files and chose "Show in Explorer". Make copies of any files that have changed or the entire project to be safe. In Android Studio Delete all conflicting/erroring objects. VCS -> Git -> Reset Head WARNING: This will reset everything to the last time you did a commit to head. Once this is complete, just to be sure: Close the project, close Android studio, then reopened both. Create new classes to replace the deleted conflicting objects with the correct name. Replace the contents of these files, or copy/paste the backup files into the folder. Commit and push your changes now, and it should work.
Follow the link for main problem cause.
来源:https://stackoverflow.com/questions/29485350/git-case-sensitivity-error-renaming-and-committing-from-android-studio