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 即可。

相关推荐
bigHead-1 天前
Git合并操作详解:安全高效地合并远程分支
git·安全·elasticsearch
C_心欲无痕1 天前
ts - 交叉类型
前端·git·typescript
秋饼1 天前
【K8S测试程序--git地址】
git·容器·kubernetes
小龙1 天前
【Git 报错解决】本地无有效提交无法推送(`src refspec main does not match any`)
git·github·报错
小扶苏1 天前
删除git全局账号信息并设置成新的账号密码命令
git
Greg_Zhong2 天前
Git创建任务分支进行开发,最后合并主分支master【纯git命令执行过程】阐述
git
眯眼因为很困啦2 天前
GitHub Fork 协作完整流程
前端·git·前端工程化
AlexDeng2 天前
Git 中模糊搜索分支名称并创建本地跟踪分支
git
jxm_csdn2 天前
递归工程工厂:Claude Code + Git Worktrees + Tilix/Tmux 的“AI分身”编码团队
人工智能·git
码咔吧咔2 天前
Git 中 pull.rebase = true 的作用与设置方法详解
git