Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git gets file hungry every once in a while

Tags:

git

I have a recurring problem with my Git repositories. I develop in Windows and my production site is under Linux. Several times it has happened that git was showing all files tracked as modified. I thought this was because of a conf issue or conflict between Windows and Linux, but then this morning, when I checked the Linux repo, it was showing all files as modified.

To add insult to injury, the two Linux repos I use (1 for prod, 1 for test) were showing the same. I had no other choice but to commit all the files, as a hard reset or a checkout were making no changes to the working directory (yup, I pretty much sucks at this). This is the result of the commit:

Created commit #######: Git, you are so mean...
1521 files changed, 302856 insertions(+), 302856 deletions(-)

Any ideas on how to sort this out next time it happens?

like image 434
Erico Lendzian Avatar asked Dec 07 '22 08:12

Erico Lendzian


2 Answers

As Bombe says, this sounds like a line-ending problem. The simplest discussion of this that I've seen is this guide at Github.

You want to set core.autocrlf on your Windows system so that Git will automatically change line endings to CRLF when you checkout from the repo into the working directory, and conversely change all CRLFs to LF when you commit files to the repo:

$ git config --global core.autocrlf true

Then you can ensure that your repo has consistent line endings either by cloning from your Linux repo or by git reset, which checks out a fresh working copy which applies the new autocrlf setting to all the LFs:

$ git reset --hard HEAD

EDIT -- If Git doesn't recognize a file as binary, autocrlf can corrupt the file by changing what it thinks are CRLF or LFs. If your repo includes unusual binary formatted file types, declare their conversion type explicitly in .gitattributes, as described in the manpage.

like image 197
Paul Avatar answered Dec 11 '22 08:12

Paul


Sounds like a line-ending issue. Check man git-config for core.autocrlf.

like image 42
Bombe Avatar answered Dec 11 '22 09:12

Bombe