git日志中文显示异常问题
rename "check_env/\347\241\254\344\273\266\345\212\240\351\200\237\346\243\200\346\265\213/03maligpuOpenCL\350\256\241\347\256\227.py" => "check_env\345\274\200\345\217\221\347\216\257\345\242\203\346\243\200\346\265\213/\347\241\254\344\273\266\345\212\240\351\200\237\346\243\200\346\265\213/03maligpuOpenCL\350\256\241\347\256\227.py" (100%) rename "check_env/\347\241\254\344\273\266\345\212\240\351\200\237\346\243\200\346\265\21
**不需要!** Git 的全局配置只需要设置一次,对**所有仓库**都有效。
Git 配置的三个级别
1. 系统级别 (--system)
# 对所有用户生效(需要sudo)
sudo git config --system core.quotepath false
# 配置文件位置:/etc/gitconfig
2. 全局级别 (--global) ✅ 推荐使用
# 对当前用户的所有仓库生效
git config --global core.quotepath false
# 配置文件位置:~/.gitconfig
3. 仓库级别 (--local)
# 只对当前仓库生效
cd /path/to/repo
git config --local core.quotepath false
# 配置文件位置:.git/config
你只需要做一次的事情
设置全局配置(一次设置,永久生效):
# 这些设置只需要运行一次
git config --global core.quotepath false
git config --global i18n.commitencoding utf-8
git config --global i18n.logoutputencoding utf-8
# 设置用户名和邮箱(也是一次性)
git config --global user.name "你的名字"
git config --global user.email "你的邮箱@example.com"
# 设置编辑器(可选)
git config --global core.editor vim
设置环境变量(添加到 .bashrc):
# 添加到 ~/.bashrc 末尾
echo '
# Git 中文支持
export LANG=zh_CN.UTF-8
export LC_ALL=zh_CN.UTF-8
export GIT_PAGER="cat"
' >> ~/.bashrc
# 使配置生效
source ~/.bashrc
验证配置已生效
# 查看全局配置
git config --global --list
# 查看所有配置(包括系统、全局、本地)
git config --list
# 检查特定配置
git config --global --get core.quotepath
# 查看配置来源
git config --list --show-origin | grep quotepath
如果在某些仓库中配置被覆盖
如果某个仓库有特殊设置,可以查看和修改:
cd /path/to/repo
# 查看该仓库的配置
git config --local --list
# 如果发现 core.quotepath 被设置为 true
git config --local core.quotepath false
# 或者删除本地配置,使用全局配置
git config --local --unset core.quotepath
创建通用的 Git 配置脚本
创建一个 setup_git_once.sh 脚本,只需运行一次:
#!/bin/bash
echo "=== 一次性 Git 配置设置 ==="
# 设置用户信息
read -p "请输入你的姓名: " USER_NAME
read -p "请输入你的邮箱: " USER_EMAIL
git config --global user.name "$USER_NAME"
git config --global user.email "$USER_EMAIL"
# 设置编码相关
git config --global core.quotepath false
git config --global core.precomposeunicode true
git config --global i18n.commitencoding utf-8
git config --global i18n.logoutputencoding utf-8
git config --global gui.encoding utf-8
# 设置别名
git config --global alias.st "status -s"
git config --global alias.ci "commit"
git config --global alias.br "branch"
git config --global alias.co "checkout"
git config --global alias.lg "log --color --graph --pretty=format:'%C(auto)%h %d %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
# 设置推送行为
git config --global push.default simple
git config --global pull.rebase false
# 设置颜色
git config --global color.ui auto
git config --global color.status auto
git config --global color.branch auto
git config --global color.diff auto
echo -e "\n✅ 配置完成!"
echo "配置已保存到 ~/.gitconfig"
echo -e "\n当前配置:"
git config --global --list | head -20
echo -e "\n这些配置对您所有仓库都有效,无需重复设置。"
重要的:环境变量设置
环境变量需要在 ~/.bashrc 或 ~/.profile 中设置,这样每次登录都会自动加载:
# 编辑 ~/.bashrc
nano ~/.bashrc
# 添加以下内容到文件末尾
# === 中文环境设置 ===
export LANG=zh_CN.UTF-8
export LC_ALL=zh_CN.UTF-8
export LC_CTYPE=zh_CN.UTF-8
# Git 显示设置
export GIT_PAGER="cat"
# 终端设置
export TERM=xterm-256color
# 保存后,运行
source ~/.bashrc
如果你在多台机器上工作
如果你在其他机器上也需要相同的配置,可以备份和恢复:
备份配置:
# 备份 ~/.gitconfig
cp ~/.gitconfig ~/gitconfig.backup
# 备份 ~/.bashrc 中的相关设置
grep -A5 -B5 "LANG\|LC_ALL\|GIT_PAGER" ~/.bashrc > ~/git_env_settings.txt
在新机器上恢复:
# 复制配置文件
cp gitconfig.backup ~/.gitconfig
# 添加环境变量到 ~/.bashrc
cat git_env_settings.txt >> ~/.bashrc
source ~/.bashrc
总结
只需要做一次的事情:
- 运行全局 Git 配置命令(使用
--global参数) - 添加环境变量到
~/.bashrc - 设置用户信息(姓名和邮箱)
每个仓库自动继承:
- 所有使用
--global设置的配置 - 环境变量设置
- Git 别名
特殊情况需要单独配置:
- 不同项目的不同用户信息(公司项目和个人项目)
- 特定仓库的特殊行为(如不同的合并策略)
对于你的灵芯派,只需要运行一次:
# 1. 设置全局配置
git config --global core.quotepath false
git config --global i18n.commitencoding utf-8
git config --global i18n.logoutputencoding utf-8
# 2. 设置环境变量(添加到 ~/.bashrc)
echo 'export LANG=zh_CN.UTF-8' >> ~/.bashrc
echo 'export LC_ALL=zh_CN.UTF-8' >> ~/.bashrc
source ~/.bashrc
# 3. 设置用户信息
git config --global user.name "zmrobo"
git config --global user.email "你的邮箱"
这样设置后,所有 Git 仓库都会正常显示中文,无需每个仓库重复设置。

浙公网安备 33010602011771号