How to configure git / PhpStorm to ignore CRLF changes

407 views Asked by At

I have a problem with PhpStorm and git.

Every time when I add files from e.g. backup archives of my server, PhpStorm shows all files as changed even if the only change is the line ending and no content.

I noticed that this comes, because my git is configured to use CRLF for checked out files and LF for files in the repo (and that is what I want).

The problem comes now, when I add files that already have LF line breaks then all these files are displayed as "modified". When I do git add on any of these files, line breaks are in the filesystem converted and git/PhpStorm discovers that these files are identical to the repo and removes the file from the "changes" list.

But when I add a whole directory with thousands of files it is a big pain to manually add all files that are not really changed. I can't add a whole folder because I first like to remove all file changes and after this see which REAL changes are in the file content.

PhpStorm file diff

My current config is:

core.autocrlf=true
core.safecrlf=false

My question is:

Is there a way to disable the function where files are displayed as "changed" even if adding them to git will not add any changes (but keep the behavior that files in Windows have CRLF and files in repo LF)?

I already found that I can disable the "LF will be replaced by CRLF" warning in command line git, by setting core.safecrlf=false. But the files are still displayed as "changed" in PhpStorm and git status.

I found a similar question for command line git: Git status ignore line endings / identical files / windows & linux environment / dropbox / meld but none of the solutions worked for me.

1

There are 1 answers

0
Radon8472 On

I found a half usefull way, and using an anser at Git status ignore line endings I wrote a script, that walks over all files and triggers the line convert for each file that has no content changes.

git status | grep modified | cut -d' ' -f 4- | while read x; do

  echo -e -n "checking $x                                                                   \r"
 if [ "$(git --no-pager diff --ignore-cr-at-eol -- $x)" ]; then
    echo "modified: $x"
 else
   ## Add files to trigger auto clrf convert
   #git add $x
   # restore repo-state of this file to remove it from changes list
   git checkout HEAD -- $x
 fi
done

It compares the file content of changes and removed the files with identical content from the changes list.

It works nice, but takes a while to run, so I am still open for better answers. I tried 2 ways (with git add and `git checkout``) both mostly fixes the problem, I am not sure what is the best way.