git 设置

转载自:http://blog.csdn.net/kl222/article/details/32903495

系统乱码
项目中的编码统一设置为UTF-8编码。

设置系统的语言设置为 zh_UTF-8,把

export LANG=zh_CN.UTF-8

保存到~/.profile文件中。

$ env|grep LANG
LANG=zh_CN.UTF-8

使用 git add 命令添加文件名含中文字符的文件时
乱码类似:

\316\304\261\276\316\304\265\265.txt
解决方案:

编辑C:\Git\etc\inputrc文件中对应的行,
查找以下2行,并修改其值,
原先:

set output-meta off set convert-meta on
改为:

set output-meta onset convert-meta off
使用git log查看含有中文的log信息时
乱码类似:

<94><96><87><9C><96><87>
解决方案:

在Bash提示符下输入:

git config –global i18n.commitencoding utf-8
git config –global i18n.logoutputencoding gbk

注:设置commit提交时使用utf-8编码,可避免Linux服务器上乱码;同时设置在执行git log时将utf-8编码转换成gbk编码,以解决乱码问题。因为windows系统默认编码为gbk。
编辑C:\Git\etc\profile文件,添加如下一行:

export LESSCHARSET=utf-8
注:以使git log可以正常显示中文(需要配合:i18n.logoutputencoding gbk)

如果系统设置了:

export LANG=zh_CN.UTF-8

则日志输出编码设置为utf-8

git config –global i18n.logoutputencoding utf-8

使用ls命令查看含有中文的文件名乱码时
乱码类似:

????.txt
解决方案:

使用 ls –show-control-chars 命令来强制使用控制台字符编码显示文件名,即可查看中文文件名。
为了方便使用,可以编辑 C:\Git\etc\git-completion.bash 文件,添加如下一行:

alias ls=”ls –show-control-chars”
在Git Gui中查看UTF-8编码的文本文件时
乱码类似:

锘夸腑鏂囨枃妗£
解决方案:

在Bash提示符下输入:

git config –global gui.encoding utf-8
注:通过上述设置,UTF-8编码的文本文件可以正常查看,但是GBK编码的文件将会乱码,所以还是没有从根本上解决问题。

可行的方法之一为:将所有文本文件的编码统一为UTF-8或GBK,然后设置相应的gui.encoding参数为utf-8或gbk。

git status乱码
git config –global core.quotepath false

或者编辑git配置文件:vi ~/.gitconfig

[core]
quotepath = false
作用:没有这一条,$git status输出中文会显示为UNICODE编码。

回车符设置
git config –global core.autocrlf false

git config –global core.safecrlf true

或者编辑git配置文件:vi ~/.gitconfig

[core]
autocrlf = false
safecrlf = true

用户信息设置
git config –global user.name KangLin
git config –global user.email kl222@126.com
或者编辑git配置文件:vi ~/.gitconfig

[user]
name = KangLin
email = kl222@126.com
设置git默认编辑器
git config –global core.editor vim
或者编辑git配置文件:vi ~/.gitconfig

[core]
editor = vim
彩色的 git 输出:
git config –global color.ui true
或者编辑git配置文件:vi ~/.gitconfig

[color]
ui = true

参考资料:
git - 简易指南
Git 参考手册
Pro Git
Git Magic
GotGitHub
Mercurial 使用教程
HgInit (中文版)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值