Solution for git modifying unintended files
I’m using MacOS and when I need to work with a project in my company (a very big repo). After cloned it to my laptop, I checked out the develop branch. Immediately, I saw some files were being modified even though I haven’t touched to them yet.
It showed some ttf
files, and even a java
file were modified. I have tried many different ways to “reset” those files
git reset --hard
or
git checkout -- .
but these command didn’t work.
Git automatically modified files unexpectedly after checking out. And I can’t discard these files from the commit.
Initial Trying
Initially, I thought the issue was something with having a core.autocrlf
that it can change EOL (end of lines) characters even for (binary) documents that should not be touched.
Thus, I tried
git config --global core.autocrlf false
and then cloned again the repo.
I also tried to add .gitattributes
file for that.
However the problem was still insisted.
Solution
After investigating, I found out the problem was because of the file system of MacOS, and we need to store the repo in a case sensitive disk format.
- Open Disk Utilities
- Click on + sign
- Choose APFS (Case Sensitive)
- Type any «name»
- Click on size option
- Put maybe 50 GB or even 10 GB is enough for both
- Copy the repo or clone it again to /Volumes/«name»
- Then you can
git stash
there (if needed)
This solution worked for me, I hope it will solve your similar issue as well.