0

I am having an issue with git. it keeps telling me that I have unstagged file.

even after git reset --hard or git add --all it still shows the file as unstagged.

I am using android studio4.0

enter image description here

P.S. tried all the answers here and none of them worked for me

Remon Shehatta
  • 1,324
  • 1
  • 10
  • 21
  • Most likely it was committed with different cased letters in an OS/FS that distinguishes between different cased names. And windows does not. Check it out in linux and see how it should look and if it's even just one file with that very name (case insensitive). – zerkms Jun 16 '20 at 00:53
  • different cased letters is a possibility. but all the team is using Windows OS. any idea how to fix this? renaming the file would do it? – Remon Shehatta Jun 16 '20 at 00:55
  • First would be better to diagnose it properly: I'd check it out on linux for that. – zerkms Jun 16 '20 at 01:12
  • Try to do it on winfows without git bash but with cmd... – dan1st Jun 16 '20 at 05:06
  • @zerkms what exactly should I check on Linux? – Remon Shehatta Jun 16 '20 at 09:59
  • @dan1st Tried to do it with cmd as admin ..same issue – Remon Shehatta Jun 16 '20 at 09:59
  • @RemonShehatta the **exact** full path (all the directories + the file itself) name, plus if any of directories in path or the file itself exist multiple times (with different cases). – zerkms Jun 16 '20 at 11:09
  • Delete the file and restore it from git? – dan1st Jun 16 '20 at 15:33
  • You could try to delete the content of the repository and execute `git reset --hard` – dan1st Jun 18 '20 at 04:56

3 Answers3

1

This is a case sensitivity in the filename issue : as you can see once the incriminated file is named OnTime_User_Presenter.kt, once it is named onTime_user_presenter.kt.

This means that, somehow, one commit was created in your git repo where the two names coexisted.

You can confirm what git has stored as a list of file :

# you should see the two capitalizations in the command's output :
git ls-tree HEAD -- longdir/

You can search with git log when this happened :

git log --graph --oneline --name-status -- longdir/onTime_user_presenter.kt longdir/OnTime_User_Presenter.kt

One way to fix this :

  1. check that the file you want to keep has the correct content,
  2. fix the content of your branches (see command below),
  3. make everyone pull the latest branches, rebase their work on top of the expected branches, and run the renaming command below

One way to make sure the correct naming ends up on both your disk and the index is :

git mv <bad_capitalization> foo
git mv foo <good_capitalization>

For step 2., on each branch you want to fix, run the above command, commit the content and push to your central repo.

If you are several to work with the repo, step 3. is important so that someone with a messed up filename does not push yet again the wrongly named file.

LeGEC
  • 46,477
  • 5
  • 57
  • 104
0

Here is another possible workaround for the case insensitivity issue (on windows).

The problem is that windows uses case insensitive directories by default but that can be changed per directory.

So, just make the directory case sensitive.

Obviously, you need to decide whether you want a case sensitive directory or not. Programs/scripts made specifically for Windows may not work any more because they could rely on a case sensitive file system. (See the comments)

If you use this solution, make sure that everything you use in this directory continues working.

Windows provides a utility program for file system operations named fsutil.

Open cmd, cd into the repository and execute the following:

fsutil file setCaseSensitiveInfo . enable

See this site for details.

If you want to restore the default (case insensitive) behaviour, you can just execute:

fsutil file setCaseSensitiveInfo . disable
dan1st
  • 12,568
  • 8
  • 34
  • 67
  • A word of warning : this would make changes that could break *other* software. – LeGEC Jun 17 '20 at 07:25
  • e.g : if other programs expect that `mydoc.docx`, `MYDOC.DOCX` and `MyDoc.docx` will open or write to the same document, well, it wouldn't anymore. – LeGEC Jun 17 '20 at 07:27
-2

If you want to discard all unstaged files , try this :

git checkout -- .