Git 常见问题排查
1 修复 git 中文显示乱码
git config --global gui.encoding utf-8
export LESSCHARSET=utf-8
Mac 下还需要关闭 core.quotepath(否则中文文件名会被转义成八进制序列显示):
git config --global core.quotepath false
如果还不好使,在 ~/.zshrc 中添加:
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
2 fatal: bad default revision ‘HEAD’
当前仓库缺少 master 分支的上游跟踪配置。执行 git config -e 添加:
[branch "master"]
remote = origin
merge = refs/heads/master
然后:
git pull
3 Git 补全脚本报错:unknown option: –list-cmds=list-mainporcelain,…
现象:git 补全登录 shell 时提示
unknown option: --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config原因:本机 git 的版本 与
git-prompt.sh/git-completion.bash的版本不一致。解决:下载与当前 git 版本一致的补全脚本:
wget https://raw.githubusercontent.com/git/git/v$(git version | cut -d " " -f 3)/contrib/completion/git-completion.bash
4 git https 无法 clone 代码
关闭 SSL 校验(仅在可信内网环境使用,不推荐在公网关闭):
git config --global http.sslVerify false
5 提示无法完成认证
The authenticity of host '[icode.example.com]:8235 ([10.0.2.15]:8235)' can't be established.
RSA key fingerprint is SHA256:... .
Are you sure you want to continue connecting (yes/no)?
原因:没有把本机公钥添加到代码托管平台的 SSH 公钥列表。
解决:
ssh-keygen -t rsa
# 将 ~/.ssh/id_rsa.pub 的内容粘贴到代码托管平台(如 icode/GitLab/GitHub)的 SSH 公钥设置中
6 更改默认提交文件大小 100M 限制
当推送大文件时报 RPC failed; HTTP 413 curl 22 The requested URL returned error: 413 之类的错误时,可调大 http.postBuffer:
git config http.postBuffer 524288000
7 其他常见提示
7.1 查看更多有用的配置项
git config -l --show-origin # 查看当前生效的所有配置及来源
git config --global core.editor vim
7.2 大文件提交建议使用 Git LFS
超过约 100MB 的文件应改用 Git LFS 管理,而不是调大 postBuffer:
git lfs install
git lfs track "*.zip"
git add .gitattributes
阅读 —
·
全站 —