You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Github.com无法渲染换行显示^M符号,配置调整无效求助

Fixing Git ^M Line Ending Issue on Windows with PHPStorm

Hey there, let's tackle this line ending problem you're facing with Git on Windows! That ^M symbol you're seeing in diffs is the Windows-style carriage return (CR) character, which pops up when Git encounters mixed line endings or misconfigured newline handling. Here are some targeted fixes to resolve this:

1. Verify Your Git Line Ending Configs

First, double-check your current Git settings to rule out conflicting configurations. Run this command in your terminal:

git config --global --list

Look for core.autocrlf and core.eol. Since you're on Windows, core.autocrlf=true is the right call (it converts CRLF to LF on commit, and LF to CRLF on checkout), but adding an explicit core.eol setting can help lock things in:

git config --global core.eol crlf

2. Normalize Existing Files in Your Repository

Your existing files might already have mixed line endings that your previous config changes didn't fix. Let's reset and reprocess all files properly:

# First, stash any uncommitted changes to keep them safe
git stash

# Remove all files from Git's cache (this doesn't delete your local files)
git rm --cached -r .

# Reset your working directory to match the latest commit
git reset --hard

# Re-add all files to the cache, letting Git apply your line ending rules
git add .

# Commit the normalized line endings
git commit -m "Normalize line endings to resolve ^M characters"

3. Fix PHPStorm's Line Separator Settings

PHPStorm might be saving files with inconsistent line endings, overriding your Git config. Adjust this setting:

  • Open Settings (File > Settings)
  • Navigate to Editor > Code Style > General
  • Under Line separator, select Windows (CRLF) (or match your project's required line ending)
  • Click Apply and OK

Make sure to re-save any files you've edited after changing this setting to ensure they use the correct line endings.

4. Check for .gitattributes File

If your project has a .gitattributes file, it might be overriding your global Git config. Ensure it has the correct line ending rules for PHP files:

*.php text eol=crlf

This forces PHP files to use CRLF line endings regardless of global settings. If you don't have a .gitattributes file, create one at the root of your repository with this line.

After following these steps, your diffs should no longer show those annoying ^M symbols. Let me know if you run into any hiccups!

内容的提问来源于stack exchange,提问作者Lukas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:33:52