1. 背景介绍
团队使用 Gitlab 管理代码,按照以下结构部署:
- Nginx 反向代理,转发到 Gitlab Docker
- Gitlab Docker + Docker Volume
最近 Push 代码时经常发生 413
错误,详细错误信息如下:
POST git-receive-pack (chunked)
error: RPC failed; result=22, HTTP code = 413
发生 413
错误通常有以下两种情况:
- 单个文件太大
- 单个 commit 包含太多的文件,例:项目初始阶段添加的第三方 JAR / SO 文件
解决方案
- Change protocol from http(s) to git/ssh
- Increase git http post buffer size
- Increase server (nginx) buffer size
2. 原因分析
2.1. 查找大文件
find . -size +10M
2.2. 待 Push 文件列表
git diff --stat --cached origin/master
2.3. 查看当前 postBuffer 值
Run this command in root folder of git repository ( by doing so you will search in ~/.gitconfig
and .git/config
files ):
git config --get http.postBuffer
3. 解决方案
3.1. 增加 postBuffer
打开 SourceTree 右上角的 Settings
- Advanced
- Edit Config File ...
打开配置文件,添加如下配置
[http]
postBuffer = 524288000
3.2. 增加 client_max_body_size
gitlab.conf
location / {
client_max_body_size 50M;
}
docker-compose.yml
version: '3'
services:
web:
environment:
GITLAB_OMNIBUS_CONFIG: |
nginx['client_max_body_size'] = '50m'
4. 参考资料
git–push large commits over http fail http://mahingupta.com/gitpush-large-commits-over-http-fail/
Push large commit over http fails https://github.com/gitlabhq/gitlabhq/issues/3099
How can I see what I am about to push with git?
https://stackoverflow.com/questions/3636914/how-can-i-see-what-i-am-about-to-push-with-git
How to check post buffer size before clone git repository? https://stackoverflow.com/questions/32137388/how-to-check-post-buffer-size-before-clone-git-repository
使用 SourceTree 出现 POST git-receive-pack (chunked) 解决方案 http://www.jianshu.com/p/75d130a03641