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

后端 未结 8 1397
遇见更好的自我
遇见更好的自我 2020-12-31 08:18


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:

相关标签:
8条回答
  • 2020-12-31 09:03

    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

    0 讨论(0)
  • 2020-12-31 09:03

    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.

    0 讨论(0)
  • 2020-12-31 09:06

    I had a similar problem and i fixed it changing git config:

    git config core.ignorecase false
    
    0 讨论(0)
  • 2020-12-31 09:14

    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'
    
    0 讨论(0)
  • 2020-12-31 09:14

    A really simple fix I found was to do this command in terminal

    git reset

    0 讨论(0)
  • 2020-12-31 09:22

    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 !

    0 讨论(0)
提交回复
热议问题