Reputation: 310
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
Upvotes: 1
Views: 1799
Reputation: 10006
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.
Upvotes: 0
Reputation: 6200
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.
Upvotes: 0
Reputation:
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:
git ls-files
is your friend here);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.
Upvotes: 1
Reputation: 310
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
Upvotes: 0