git diff 输出空,但 git status 提示 Motified(M)解决办法

问题

当把在 Windows 系统上 Clone 下来的项目传到 Linux 服务器上时,发现所有文件都提示 Modified(M)。

原因:Windows 系统 Clone 下来的项目默认会用 CRLF 格式换行,但传到服务器上时与 .git 的 LF 格式不符(存在多余的^M)。

但直接在 VScode 里修改成 LF 格式或用 dos2unix 转换后,依然提示 Motified。(此时 git diff 输出空,但 git status 提示 Motified)

可能是因为这样转换时,git 会认为修改了文件

解决方案

输入命令 git config core.autocrlf truegit config --global core.autocrlf true 即可。

相关推荐
Irene19919 小时前
查看是否已安装 Git 的方法
git
my_power5209 小时前
检出git项目到android studio该如何配置
android·git·android studio
安果移不动9 小时前
Git 实战:如何优雅地撤销历史中的某一个 Commit?
git
啥都不懂的小小白12 小时前
Git 入门指南:从零开始掌握版本控制
git
AI逐月12 小时前
Git 彻底清除历史记录
大数据·git·elasticsearch
有什么东东14 小时前
Windows安装git教程以及初步使用
git
不爱吃米饭_14 小时前
Gitea 轻量级的Git方案 - Gitlab的替代品
git·gitlab·gitea
CoderJia程序员甲16 小时前
GitHub 热榜项目 - 日榜(2025-12-15)
git·ai·开源·llm·github
大柏怎么被偷了17 小时前
【Git】远程操作
git
studytosky18 小时前
Linux 基础开发工具(3):Git 控制与 GDB 调试实用指南
linux·运维·服务器·网络·数据库·git