cd491415
cd491415

Reputation: 891

git on Mac sees files I havent touched as modified and they also appear as staged already

I am seeing strange behavior on Mac with git. I dont see this happening on Windows. Using git v 2.19.1 on mac and 2.18.0.windows.1 on windows.

I work in a crossplatform team, so some of us use Windows, others use Mac. I use both.

Here is the scenario I see:

I work on my feature branch for few days and like to make sure I update my branch with latest changes on remote so I always work on most recent version of remote. So, I daily do following to reduce chance of conflicts and stay on most recent version:

git checkout develop
git fetch origin
git merge origin/develop 
git checkout my-feature
git merge develop 

Once that is done, I apply my changes to my-feature branch but I notice that git behaves very strangely on Mac. Here is what happens:

For example, git status shows my .gitignore file now as:

me$ git status
On branch my-feature
Your branch is up to date with 'origin/my-feature'.

Changes to be committed:
  new file:  .gitignore

On Windows, this does not happen and since I did not modify this file, it will not show in git status at all. My modified files show as needed to be added which is how it should behave.

Why would files I never touched be viewed by git on Mac as somehow modified and staged?

Upvotes: 0

Views: 863

Answers (1)

benhorgen
benhorgen

Reputation: 1965

In mixed dev environments (like I work in also) I see this behavior when 'line endings' are mismatched. The best way to solve this is to update your .gitconfig file.

I encourage everyone on the teams I work within to add the following to their .gitconfig file. You can add a .gitconfig to each repo, just like a .gitignore, and/or each developer can set it within their git global config file.

[text]
   eof=lf

There are different options, but the key is for the whole team to use the same line endings when committing & pulling.

Here is my gitconfig, per the request below.

[User]
    name = Ben Horgen
    email = [email protected]
[text]
    eof=lf
[core]
    autocrlf = input    
[pull]
    rebase = true
[push]
    default = simple

Upvotes: 2

Related Questions