Files showing as modified directly after a Git clone

GitGit Clone

Git Problem Overview


I'm having an issue with a repository at the moment, and though my Git-fu is usually good, I can't seem to solve this issue.

When I clone this repository, then cd into the repository, git status shows several files as changed. Note: I haven't opened the repository in any editor or anything.

I tried following this guide: http://help.github.com/dealing-with-lineendings/, but this didn't help at all with my issue.

I have tried git checkout -- . many times, but it seems not to do anything.

I'm on a Mac, and there are no submodules in the repository itself.

The filesystem is "Journaled HFS+" filesystem on the Mac and is not case-sensitive. The files are one-line and about 79 KB each (yes, you heard right), so looking at git diff isn't particularly helpful. I have heard about doing git config --global core.trustctime false which might help, which I will try when I get back to the computer with the repository on it.

I changed details of filesystem with facts! And I tried the git config --global core.trustctime false trick which didn't work very well.

Git Solutions


Solution 1 - Git

I had the same problem on the Mac after cloning a repository. It would assume all files had been changed.

After running git config --global core.autocrlf input, it was still marking all files as changed. After looking for a fix I came across .gitattributes file in the home directory which had the following.

* text=auto

I commented it out and any other cloned repositories from now on were working fine.

Solution 2 - Git

I got it. All the other developers are on Ubuntu (I think) and thus have case-sensitive file systems. I, however, do not (as I'm on a Mac). Indeed, all the files had lowercase twins when I took a look at them using git ls-tree HEAD <path>.

I'll get one of them to sort it out.

Solution 3 - Git

git config core.fileMode false

solved this problem in my case

https://git-scm.com/docs/git-config

TL;DR;

core.fileMode

If false, the executable bit differences between the index and the working tree are ignored; useful on broken filesystems like FAT. See git-update-index(1).

The default is true, except git-clone(1) or git-init(1) will probe and set core.fileMode false if appropriate when the repository is created.

Solution 4 - Git

I assume you are using Windows. That GitHub page you linked to has the details backwards. The problem is that CR + LF line endings have been committed to the repository already and because you have core.autocrlf set to either true or input, Git wants to convert the line-endings to LF, so git status shows that every file is changed.

If this is a repository that you only want to access, but have no involvement with, you can run the following command to merely hide the issue without actually solving it.

git config core.autocrlf false


If this is a repository that you will be actively involved in and can commit changes to. You may wish to fix the problem by making a commit that changes all the line endings in the repository to use LF instead of CR + LF and then take steps to prevent it from happening again in the future.

The following is taken directly from the gitattributes man page and should be preformed from a clean working directory.

echo "* text=auto" >>.gitattributes
rm .git/index     # Remove the index to force Git to
git reset         # re-scan the working directory.
git status        # Show files that will be normalized.
git add -u
git add .gitattributes
git commit -m "Introduce end-of-line normalization"

If any files that should not be normalized show up in git status, unset their text attribute before running git add -u.

manual.pdf      -text

Conversely, text files that Git does not detect can have normalization enabled manually.

weirdchars.txt  text

Solution 5 - Git

Please run the following commands. That might solve the issue.

# Remove everything from the index.
git rm --cached -r .

# Write both the index and working directory from git's database.
git reset --hard

Solution 6 - Git

In Visual Studio, if you are using Git, you can auto generate the .gitignore and .gitattributes files. The auto generated .getattributes file has the following line:

* text=auto

This line is near the top of the file. We just needed to comment the line out by adding a # to the front of it. After doing that, things operated as expected.

Solution 7 - Git

The problem might also arise from differing file permissions, as was my case:

Fresh cloned repository (Windows, Cygwin):

$ git ls-tree HEAD
100755 blob 8099ea496a2c78d71125d79a05855f60ebf07904    testfile
   ↑↑↑

Bare remote repository (Linux):

$ git ls-tree HEAD
100644 blob 8099ea496a2c78d71125d79a05855f60ebf07904    testfile
   ↑↑↑

Solution 8 - Git

I wanted to add an answer more directed on "Why" this happens, because there is already a good answer on how to fix it.

So, .gitattributes has a * text=auto setting, which causes this issue.

In my case, files on GitHub’s master branch had \r\n endings. I have dialed up the settings on the repository to check-in with \n endings. I don't know what Git checks out though. It is supposed to check out with native endings onto my Linux box (\n), but I guess it checked out the file with \r\n endings. Git complains because it sees the checked out \r\n endings that were in the repository and warns me that it will check in \n settings. Hence files are "to be modified".

That's my understanding for now.

Solution 9 - Git

The same issue for me. I could see several images with the same name, like "textField.png" and "textfield.png" in the remote Git repository, but not on my local repository. I was only able to see "textField.png" which was not used in the project's code.

It turns out most of my colleagues are on Ubuntu using ext4 filesystem whereas I'm on a Mac using APFS.

Thanks to Sam Elliott's answer, the solution was quite simple. First I asked a colleague on Ubuntu to delete the redundant file versions with the uppercase, then commit and push on remote.

Then I ran the following:

# Remove everything from the index.
git rm --cached -r .

# Write both the index and working directory from git's database.
git reset --hard

Finally, we decided that every developer should change his Git configuration to prevent this to ever happen again:

# Local Git configuration
git config core.ignorecase true

or

# Global Git configuration
git config --global core.ignorecase true

Solution 10 - Git

I had the same problem. Also with a Mac. Looking at the repository on a Linux machine I noticed that I had two files:

geoip.dat and GeoIP.dat

I removed the deprecated one on the Linux machine and cloned the repository again to the Mac. I was not able to pull, commit, stash or pull from my copy of the repository when there were duplicates.

Solution 11 - Git

I also just had the same problem. In my case I cloned the repository and some files were immediately missing.

This was caused by the path to the file and the filename being too long for Windows. To resolve it, clone the repository as close to the hard disk drive root as possible to reduce the length of the path to the file. For example, clone it to C:\A\GitRepo instead of C:\Users Documents\yyy\Desktop\GitRepo.

Solution 12 - Git

Edit the file called .git/config:

sudo gedit .git/config

Or:

sudo vim .git/config

###Contents

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true

[remote "origin"]
    url = [email protected]:DigitalPlumbing/unicorn-magento.git
    fetch = +refs/heads/*:refs/remotes/origin/*

[branch "master"]
    remote = origin
    merge = refs/heads/master

[branch "productapproval"]
    remote = origin
    merge = refs/heads/productapproval

Change filemode=true into filemode = false.

Solution 13 - Git

I was trying to do an interactive rebase, but it claimed there were some modified files, so it wouldn't let me do it right now. I tried everything to get back to a clean repository, but nothing worked. None of the other answers helped. But this finally worked...

git rm -rf the-folder-with-modified-stuff
git ci -m 'WAT'

Boom! Clean repository. Problem solved. Then I just had to drop the last commit when I did my rebase -i and finally everything was clean again. Bizarre!

Solution 14 - Git

For new versions of macOS this can be caused by a security feature of the OS.

In the repository I was working on, there was a binary file which had *.app as file type.

It was just some serialised data, but macOS treats all *.app files as an application and as this file was not downloaded by the user, the system deemed it insecure and added the com.apple.quarantine file attribute which makes sure the file can not be executed.

But setting this attribute on the file was also changing the file and it therefore showed up in the Git change set without any way of reverting it.

You can check if you have the same problem by running $ xattr file.app.

The solution is pretty simple, as long as you don't have to work with the file. Just add *.app binary to your .gitattributes.

Solution 15 - Git

The issue for me is that on my MacBook, my Mac was not tracking by case. I created an APFS case-sensitive "Workspace" partition. After that, I was no longer getting the status errors.

Solution 16 - Git

I copied my local repository to another folder and a bunch of modified files showed up. My workaround was: I stashed the modified files and deleted the stash. The repository became clean.

Solution 17 - Git

I found that Git was treating my files (.psd in this case) as text. Setting it to a binary type in the .gitattributes solved it.

*.psd binary

Solution 18 - Git

Just in case it helps someone else, there can be another cause for this problem: differing versions of Git. I was using the default installed version of Git on a Ubuntu 18.04 (Bionic Beaver) box and everything was working fine, but when trying to clone the repository using Git on Ubuntu 16.04, some files were showing up as modified.

None of the other answers here fixed my problem, but upgrading the versions of Git to match on both systems did fix the problem.

Solution 19 - Git

I had a related issue on MacOS.

That is, some may not realize that, though it appears that MacOS’ file system is case sensitive, it isn’t. It will store mixed case file names but, for example, consider Foo.py and foo.py to be the same file.

A colleague had created just such a scenario by making a foo.py from a Foo.py as part of a development scaffolding. (I.e., not only enforcing PEP8 module file naming conventions, but refactoring the contents significantly from the original such that we wanted to do that kind of work in parallel). When I pulled those changes, MacOS overwrote all the modifications from foo.py into Foo.py, which caused git to think I had made local changes, when I hadn't. When doing a fresh clone, git immediately claimed that Foo.py had significant changes even though it was a fresh clone.

The solution was to rename foo.py to an entirely different file name that in no way conflicted with the original. The problem went away with a fresh clone of the repository after making that change.

(There is a system configuration flag to turn on case sensitive behavior for MacOS, but it is recommended to leave it in the default setting as toggling the behavior may break things that expect the case insensitive behavior.)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSam ElliottView Question on Stackoverflow
Solution 1 - GitadnansView Answer on Stackoverflow
Solution 2 - GitSam ElliottView Answer on Stackoverflow
Solution 3 - GitPiotr KorlagaView Answer on Stackoverflow
Solution 4 - GitArrowmasterView Answer on Stackoverflow
Solution 5 - GitkdsView Answer on Stackoverflow
Solution 6 - GitJ Adam RogersView Answer on Stackoverflow
Solution 7 - GitGimaView Answer on Stackoverflow
Solution 8 - GitDennisView Answer on Stackoverflow
Solution 9 - GitAdrianView Answer on Stackoverflow
Solution 10 - Gituser2148301View Answer on Stackoverflow
Solution 11 - Git8bitmeView Answer on Stackoverflow
Solution 12 - GitPramod KharadeView Answer on Stackoverflow
Solution 13 - GitThomas AylottView Answer on Stackoverflow
Solution 14 - GitLukas ZechView Answer on Stackoverflow
Solution 15 - GitKyle SmithView Answer on Stackoverflow
Solution 16 - GitOleg ShvetsovView Answer on Stackoverflow
Solution 17 - GitLannyView Answer on Stackoverflow
Solution 18 - GitTodd ChaffeeView Answer on Stackoverflow
Solution 19 - GitMark ColettiView Answer on Stackoverflow