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

Git Bash执行git status报错:无法访问配置文件,HOME变量异常

解决Git Bash执行git status时的路径访问错误

问题细节

执行git status时触发报错:

fatal: unable to access 'C:\Users?artolomeo/.config/git/config': Invalid argument

Windows用户名为bartolomeo,此前无同类错误。Git Bash中执行echo $HOME返回C:\Userartolomeo,执行set HOME=C:\Users\bartolomeo无任何变化;但cmd中echo %HOME%显示正确路径C:\Users\bartolomeo。

解决步骤

  • 修正Git Bash的HOME环境变量配置
    打开Git Bash,编辑用户目录下的.bashrc或.profile文件(无则新建),添加:

    export HOME="/c/Users/bartolomeo"
    

    保存后执行source ~/.bashrc(若编辑的是.profile则执行source ~/.profile),再用echo $HOME验证路径是否恢复正常。

  • 手动指定Git全局配置文件路径
    先确认C:\Users\bartolomeo\.config\git目录存在,不存在则手动创建。执行以下命令绑定正确的配置文件:

    git config --file "/c/Users/bartolomeo/.config/git/config" --global user.name "你的用户名"
    git config --file "/c/Users/bartolomeo/.config/git/config" --global user.email "你的邮箱"
    

    完成后重试git status。

  • 强制Git Bash加载用户配置
    右键Git Bash快捷方式,选择「属性」,在「目标」栏末尾添加 --login(注意前方空格),确定后重新打开Git Bash,强制加载用户级配置文件。

  • 排查字符编码异常
    若上述方法无效,在.bashrc中添加字符编码配置:

    export LC_ALL=C.UTF-8
    export LANG=C.UTF-8
    

    执行source ~/.bashrc后再次测试命令。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 19:17:09