解决git在Windows下的乱码问题--解决代码从git 拉下来之后中文乱码的问题

Contents

  1. 1. 设置 Git 支持 utf-8 编码
  2. 2. 让 ls 命令可以显示中文名称

在Linux及托管网站上默认的编码都是utf-8,而Windows系统默认编码不是采用utf-8,所以Git 客户端在Windows下总是会有一些问题。一个解决方案就是通过设置git编码为utf-8。

 

设置 Git 支持 utf-8 编码

在命令行下输入以下命令:

1
2
3
4
5
6
$ git config --global core.quotepath false          # 显示 status 编码
$ git config --global gui.encoding utf-8            # 图形界面编码
$ git config --global i18n.commit.encoding utf-8    # 提交信息编码
$ git config --global i18n.logoutputencoding utf-8  # 输出 log 编码
$ export LESSCHARSET=utf-8
# 最后一条命令是因为 git log 默认使用 less 分页,所以需要 bash 对 less 命令进行 utf-8 编码

以上命令等效于:
在 etc\gitconfig 中添加

[core]
    quotepath = false
[gui]
    encoding = utf-8
[i18n]
    commitencoding = utf-8
    logoutputencoding = utf-


在etc\profile 中添加

export LESSCHARSET=utf-8


说明:

  1. gui.encoding = utf-8 解决在 $ git gui 和 gitk 里中文乱码。如果发现代码中的注释显示乱码,可以设置项目根目录中.git/config文件添加
    1
    2
    [gui]
        encoding = utf-8
  2. i18n.commitencoding = utf-8 设置 commit log 提交时使用 utf-8 编码,可避免服务器上乱码,同时与Unix上的提交保持一致!
  3. i18n.logoutputencoding = gbk 使得在 $ git log 时编码设置为 utf-8
  4. export LESSCHARSET=utf-8使得 $ git log 可以正常显示中文(配合i18n.logoutputencoding 的设置)

让 ls 命令可以显示中文名称

修改 etc\git-completion.bash 文件:

1
alias ls="ls --show-control-chars --color"

这样设置后,基本可以解决中文显示的问题。

本文参考了解决 Git 在 windows 下中文乱码的问题MsysGit乱码与跨平台版本管理 

另外也可以参考博文

http://xstarcd.github.io/wiki/shell/git_chinese.html

转载于:https://my.oschina.net/u/2308739/blog/736179

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值