git status shows as files modified directly after clones
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Problem
git status shows some of the files as modified after the clone without making any local changes. Following appears when a git status is run
[user@myhost ~]$ git clone -b release/3.10.2 ssh://git@stash.myhost.com/myproj/repo.git
Cloning into 'repo'...
remote: Counting objects: 351985, done.
remote: Compressing objects: 100% (133993/133993), done.
remote: Total 351985 (delta 176642), reused 341876 (delta 168250)
Receiving objects: 100% (351985/351985), 293.39 MiB | 4.41 MiB/s, done.
Resolving deltas: 100% (176642/176642), done.
Checking connectivity... done.
[user@myhost ~]$ cd repo
[user@myhost ~]$ git status
On branch release/3.10.2
Your branch is up-to-date with 'origin/release/3.10.2'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: my-backend/configuration/config/dev1/properties-key.xml
modified: my-backend/configuration/config/dev2/properties-key.xml
modified: my-backend/configuration/config/local/properties-key.xml
no changes added to commit (use "git add" and/or "git commit -a")
Cause
- The behavior which showing some files as modified could be related to line ending setting and multiple client used. Every operating system handles line endings in it's own way. So if you are working on repositry where in the the files are edited in multiple operating systems, you may see unexpected results.
- a .gitattributes file added to the root of the repo. It will override individual client settings and may trigger a line ending change after the clone.
Resolution
For cause 1
You can change how Git handles line endings by git config core.autocrlf
command is used to change. It takes a single argument.
git config --global core.autocrlf input
# Configure Git on <your os> to properly handle line endings
For cause 2
Verify your if there any .gitattributes file that trigger line ending changes. It overrides an client's core.autocrlf
setting, to ensure a consistent behavior for all users, regardless of their Git settings.
You can find more details about .gitattributes here.