【问题记录】解决“命令行终端”和“Git Bash”操作本地Git仓库时出现 中文乱码 的问题!

  • 在使用 “命令行终端” 和 “Git Bash” 在本地Git仓库敲击命令时,对中文名称文件显示一连串的数字,如下所示:
  • 这种情况通常是由于字符编码设置不正确所引起的

设置全局字符编码

  • 在 Git Bash 中,可以使用以下命令来设置字符编码为UTF-8:
    • git config --global core.quotepath off
    • git config --global gui.encoding utf-8
    • git config --global i18n.commit.encoding utf-8
    • git config --global i18n.logoutputencoding utf-8
  • 可以使用 git config --list 验证刚刚进行的置。
  • 然后使用 “命令行终端” 运行就可以正常显示中文了
  • 但是 “Git Bash” 没有显示一系列数字了,而是显示中文乱码问题
  • 这里还要修改 Git Bash 字符编码,按如下操作就行了
    • 打开 Git Bash 终端,然后右键点击窗口的标题栏,选择 "Options"。
    • 在 "Options" 对话框中,选择 "Text" 选项卡。
    • 在 "Locale" 部分,将字符集(Character set)设置为 UTF-8。


命令解释

  • git config --global 命令用于在Git中配置全局设置,这些设置只适用于当前用户的所有Git仓库
  • git config --global core.quotepath off
    • core.quotepath 是 Git 的一个设置,它控制是否对文件名使用引号。将其设置为 off 表示禁用引号,使得 Git 在显示文件名时不会添加引号。
    • 这个设置通常用于解决包含特殊字符或空格的文件名在 Git 中的显示问题。
  • git config --global gui.encoding utf-8
    • gui.encoding 是 Git 的一个设置,它指定了 Git 图形界面(GUI)中使用的字符编码。将其设置为 utf-8 表示使用UTF-8字符编码。
  • git config --global i18n.commit.encoding utf-8
    • i18n.commit.encoding 是 Git 的一个设置,它定义了提交消息(commit message)的字符编码。将其设置为 utf-8 表示提交消息应该使用UTF-8字符编码。
  • git config --global i18n.logoutputencoding utf-8
    • i18n.logoutputencoding 是 Git 的一个设置,它定义了 Git 日志输出的字符编码。将其设置为 utf-8 表示 Git 的输出应该使用UTF-8字符编码。

撤销全局配置项

  • 命令格式:git config --global --unset 配置项路径
  • 例如,如果要删除全局配置中的 core.quetepath,可以运行:
    • git config --global --unset core.quotepath

猜你喜欢

转载自blog.csdn.net/weixin_43729127/article/details/133185964