1

After checking out a branch (master) and git pull, I have two files appearing as modified which I can not get rid of.

I have tried everything (git stash, git checkout ., git reset, git reset --hard, git reset --hard HEAD).

Even after deleting and cloning the project again, running git status always shows the files.

What can I do? This is the result of the git status:

Mahans-MacBook-Pro:finance-service-platform Mahan$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
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:   tests/Mocks/Models/CarInsurance/PackageMock.php
    modified:   tests/mocks/Models/CarInsurance/CarSubmodelMock.php

no changes added to commit (use "git add" and/or "git commit -a")

this is also my .gitignore content:

/vendor
.env
apidoc.json
docs/*
.phpintel/
.idea
Selfish
  • 6,023
  • 4
  • 44
  • 63
  • 1
    Show us the output of `git status`. Maybe `git clean` might help. Or just go the manual way `rm file`. – Johannes Thorn Jun 07 '16 at 07:21
  • Can you provide the output of at least a few of these commands, there is a few things that could be going on here, and we will need a bit more info – Luke Exton Jun 07 '16 at 07:22
  • Also if you have a .gitignore please post the content of your gitignore file – Saverio Proto Jun 07 '16 at 07:25
  • Probably, you are confusing concepts. Sounds like you are confusing `unstaged changes` with `untracked files`, otherwise most of the commands you mentioned would remove the unstaged changes. – Alderath Jun 07 '16 at 07:29
  • i updated the question and put the responses as well. – Mahan Hazrati Sagharchi Jun 07 '16 at 07:30
  • @Alderath i'm not sure about this but what ever i'm doing, i cannot get rid of those files – Mahan Hazrati Sagharchi Jun 07 '16 at 07:31
  • 1
    Does git think you have `tests/mocks` as well as `tests/Mocks` directories? If so, and assuming you're using a Mac, you're in trouble. Fix would be to make a clone on a system with a case-sensitive filesystem, resolve the two directories into one, and carry on. –  Jun 07 '16 at 07:32
  • @tfb thanks . i'm not sure about it because we are merging lot of PRs everyday and not sure who misunderstood the standard of the project on the team. but i'm investigating this and will back to you after it – Mahan Hazrati Sagharchi Jun 07 '16 at 07:34
  • Have you tried what git status is telling you to do? `(use "git checkout -- ..." to discard changes in working directory)` – bcmcfc Jun 07 '16 at 08:02
  • @bcmcfc i did it. i also did alot of things on the net like git clean or update or many other things but nothing worked. but not sure but i think tfb's solution worked – Mahan Hazrati Sagharchi Jun 07 '16 at 08:04

4 Answers4

1

I think the problem here is that you are using a case-insensitive (but case-preserving) filesystem, on the Mac, while git is case-sensitive.

This means that it's possible, in the git repo, to have files whose (path-)names differ only in case, but it's not possible to have that in the filesystem. The result of this is that when you check out a commit, one of these files inevitably overwrites the other, and unless the files are identical, git will the always see modified files in the checkout.

The solution is not to do this: never have files whose names only differ in case if you might have to use a case-insensitive filesystem.

To resolve the problem:

  1. clone the repo onto a system with a case sensitive filesystem (Linux or other traditional Unix filesystem: not Windows, not OSX with default mount options);
  2. Find the offending files (git ls-files is your friend here);
  3. resolve the problem somehow, commit the changes and push;
  4. profit.

There may be options to git to make it detect such issues in a more helpful way: I don't know what they are if so.

0

i found the answare. thanks to @tfb i just commit the new changes that git asked and after i run the tests, everything was ok and green then i pushed to master. but again i had the same issue, but this time i run the git stash for once and then git pull it fetched my new commit and now it's ok

0

My best bet is a VERY common issue with git, which mostly appears when using the same repository on PC and Mac/Linux:

Somehow, someone probably committed those files twice. Because Windows is case insensitive when in comes to file-system, it happens that the files can be committed more than once, in different capitalization.

This drives Git insane, and the first to suffer are Mac/Linux users, who will see the two different capitalizations, one every time. Git will store the changes for the two version of the file name in the same space, but will show every version of the file separately on Mac/Linux.

Best practice to resolve this is to backup the correct version of the file, and remove it using git rm. Then commit the removal. Git will show the file once more (usually in different capitalization), remove the second instance as well until no variation of the file appears, and the file does not exist in the repository.

Then re-create the file (mind the correct capitalization) and add it to the repo using git add, and push the change. Make sure all users who still have the issue re-clone the repo after this was done.

Selfish
  • 6,023
  • 4
  • 44
  • 63
0

Another problem that can cause this problem is CRLF <-> LF conversion. If you type "git diff" you might get the message "warning: CRLF will be replaced by LF"

In this case see the answers to Git replacing LF with CRLF

In my case I was on an old version of git and got rid of the problem by upgrading git.

Bryan Larsen
  • 9,468
  • 8
  • 56
  • 46