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
相关产品推荐
相关产品推荐

