1

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.

Radon8472
  • 4,285
  • 1
  • 33
  • 41
  • I think you have a workflow problem, not a Git or PhpStorm problem. _Why_ do you frequently copy thousands of files from your Linux server to your Windows machine? The LF to CRLF conversion is only done when you do `git add`, as you've already discovered. Why can't you do a `git add .` to have this conversion happen, removing all files which only have their newlines edited, then do a `git reset` to look at the remaining changes? Have you considered running a commandline tool that does this conversion for you? – CodeCaster Oct 12 '22 at 09:45
  • @CodeCaster 1. Mostly we have this issue when creating a new repo an filling it with content of old archive files, or when we need to compare the state of server files with the state in the repo. I tried your suggestion with `git add && git reset` . It solves SOME of the issues, but only for a very small amount of files. The rest is still listed in phpstorm and commandline git. Currently I try to write a script, that walks over all files and automatically checks them. I yust hoped there is a better way with any git configs or a nice one-liner command – Radon8472 Oct 12 '22 at 12:17
  • A bit unrelated to the actual issue but still: 1) What kind of files are those (PHP / HTML / JS / etc)? 2) Why not keep them all using `LF` and only use `CRLF` for Windows-specific files (e.g. `web.config` if you are using IIS web server etc) and try not to use any line-ending conversion at all? My point: PHP handles both LF and CRLF just fine, be it on Windows on Linux/Mac. Most text editors/tools will also handle LF files (unless, perhaps, it a standard Notepad). Would that work with your code/workflow? – LazyOne Oct 12 '22 at 13:03
  • @LazyOne The files are mostly php, html, js, css and a few other text types (svg, less, json, txt ect.). Disabling line-end conversion was the way in my last company, but in the current company most people work with windows, and so all text-like files should be stored with windows linebreaks in working dir. – Radon8472 Oct 12 '22 at 15:24
  • To clean the status, you can commit those files with "No differences - only occurred for CRLF & LF". This is not a perfect solution, but it can save your time. – Wasim Mar 26 '23 at 10:49

1 Answers1

0

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.

Radon8472
  • 4,285
  • 1
  • 33
  • 41