Git 区分大小写错误——从 Android Studio 重命名和提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29485350/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git case-sensitivity error -- renaming and committing from Android Studio
提问by Ian Campbell
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:
例如,我有一个名为的文件FOOBar.java
,我想将其重命名为FooBar.java
. 尝试了很多东西后,我收到错误:
Error:error: pathspec 'app/src/main/java/blahblah/FooBar.java' did not match any file(s) known to git.
Error:error: pathspec 'app/src/main/java/blahblah/FooBar.java' did not match any file(s) known to git.
我尝试过的事情(不起作用,都产生相同的错误):
from Android Studio:来自 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 Projectbefore/after any of the above
- 使用 Git删除
FOOBar.java
、重新创建FooBar.java
、添加/提交 - 重构/重命名文件,使用 Git 添加/提交
- File--> Invalidate Caches / Restart...,然后尝试上述方法之一
- Rebuild Project在上述任何一项之前/之后
in the file system:
在文件系统中:
- deleting the
.gradle
folder in the project folder, then trying one of the above in Android Studio
- 删除
.gradle
项目文件夹中的文件夹,然后在 Android Studio 中尝试上述方法之一
from the Git command line:
从 Git 命令行:
git mv FOOBar.java FooBar.java --force
thengit commit FooBar.java -m 'renamed from FOOBar.java to FooBar.java'
git mv FOOBar.java FooBar.java --force
然后git commit FooBar.java -m 'renamed from FOOBar.java to FooBar.java'
回答by poke
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.
Windows 的文件系统大多不区分大小写,因此您不能仅通过更改大小写来重命名文件。相反,您必须在两者之间使用一个临时名称。
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'
回答by Sanket Berde
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
我找到了一个非常简单的解决方案。假设您需要将 Java 包“活动”重命名为“活动”。这个包包含几个文件和子包
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
- 将“活动”重构为“活动临时”(Shift + F6)
- 提交并推动这些更改
- 再次从“活动临时”重构为“活动”
- 提交并推动这些更改
Thats All Folks !
那是所有的人!
回答by Kaizie
I had a similar problem and i fixed it changing git config:
我遇到了类似的问题,我通过更改 git config 修复了它:
git config core.ignorecase false
回答by Bikesh M
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
我也遇到了几乎相同的情况,在我的情况下,我创建了一个文件并添加到 git (使用 git add ),在添加到 git 后我重命名了该文件。在提交时,我遇到了相同类型的错误。我通过以下步骤解决了
use git statusto see the staged files you can see your old file in the list
使用git status查看暂存文件,您可以在列表中看到旧文件
-
-
app/src/main/java/blahblah/FOOBar.java
-
-
use git resetto remove file from staging
使用git reset从暂存中删除文件
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
在此之后你可以提交
回答by Daniel Silva
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.
将文件重命名回原始文件名,然后将其重命名为不同的名称,然后重命名为具有正确大小写的文件名。Git 不会再抛出错误,它与 Poke 指出的解决方案相同,但使用的是 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.
回答by adisai1
A really simple fix I found was to do this command in terminal
我发现一个非常简单的解决方法是在终端中执行此命令
git reset
重置
回答by Paulo Pereira
Try to restartthe Android Studio!
尝试重启Android Studio!
I had this problem on a repository with no commits.
我在没有提交的存储库上遇到了这个问题。
回答by Saad Bilal
http://binaryjeremys.blogspot.com/2015/03/android-studio-doesnt-like-it-when-you.html
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.
首先备份文件:右键单击其中一个文件并选择“在资源管理器中显示”。复制任何已更改的文件或整个项目以确保安全。在 Android Studio 中删除所有冲突/错误对象。VCS -> Git -> 重置头部警告:这会将所有内容重置为您上次提交头部的时间。完成后,请确保:关闭项目,关闭 Android Studio,然后重新打开两者。创建新类以使用正确的名称替换已删除的冲突对象。替换这些文件的内容,或将备份文件复制/粘贴到文件夹中。现在提交并推送您的更改,它应该可以工作。
Follow the link for main problem cause.
按照主要问题原因的链接。