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

.gitignore无法忽略未跟踪文件:编码问题排查与解决

.gitignore失效问题排查与解决

我遇到了.gitignore无法忽略文件的问题,现有解决方案都无效,于是新建了TestRepo1仓库进行排查。环境为Windows 11系统,在VS Code的PowerShell(版本5.1,内部版本26100)终端操作,仓库结构如下:

TestRepo1\
 | .gitignore
 | logs\
 |  | dev.log

我的.gitignore内容:

logs/
*.log

除.gitignore外无任何文件被跟踪,执行git status显示.gitignore和logs/均为未跟踪状态;执行git add .gitignore并提交后,git status里logs/仍显示未跟踪,尝试添加logs\条目也无效。

执行git status --ignored显示没有文件被忽略,core.excludesfile未配置,用户.gitconfig仅设置了姓名、邮箱,core变量只有editor和autocrlf。

执行git show HEAD:.gitignore查看时,发现logs/条目变成了<FE><FE>l^@o^@g^@s^@/^@^M^@这类奇怪字符,推测是编码问题导致.gitignore失效。

将.gitignore改为UTF-8编码保存后,问题解决。

看起来VS Code默认使用UTF-8编码,但PowerShell 5.1默认是UTF-16 LE编码,这可能是问题根源,后续会单独排查PowerShell的编码设置。

现在.gitignore已正常工作。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 15:01:05