git

git add和commit一起操作 合并操作

执行git commit -am “提交描述”即可将add和commit操作合并, 不需要先git add file 再 git commit -m “提交描述” 了

-a
–all
参数作用: Tell the command to automatically stage files that have been modified and deleted, but new files you have not told Git about are not affected.

-m
–message=
参数作用 Use the given as the commit message. If multiple -m options are given, their values are concatenated as separate paragraphs.

GitHub – failed to connect to github 443 windows/ Failed to connect to gitHub – No Error

I have wide experience working with corporate proxies. Configuration is usually working well with

But if you have configured the proxy and it’s impossible to work with git (always getting 443 error) try to check if you have a remote.origin.proxy bypassing your configuration.

git config --list --show-origin

If you check that “remote.origin.proxy” is configured as empty value try to unset it or almost set it with your corporate proxy:

git config --add remote.origin.proxy "http://[yourproxy]:[yourport]"

And since several enterprise sites have untrusted certificates I recomend you to avoid certificate checking if you are using ssl:

git config http.sslverify false    
git config --global http.sslverify false

git index-pack failed

在gitlab服务器上配置

git config --global http.postBuffer 524288000

 

 

 

[pack]

windowMemory = 0
packSizeLimit = 20000m
threads = 1
deltaCacheSize = 100000m
window = 0
thread = 1
[core]
packedGitLimit = 1g
packedGitWindowSize = 1g
compression = 0
bigFileThreshold = 10g


Git把Tag推送到远程仓库

一、列出标签

$ git tag # 在控制台打印出当前仓库的所有标签

二、搜索标签

$ git tag -l ‘v0.1.*’ # 搜索符合模式的标签

三、推送标签到远程仓库

git push并不会把tag标签传送到远端服务器上,只有通过显式命令才能分享标签到远端仓库。
1.push单个tag,命令格式为:git push origin [tagname]
例如:
git push origin v1.0 #将本地v1.0的tag推送到远端服务器
2.push所有tag,命令格式为:git push [origin] –tags
例如:
git push –tags

git push origin –tags

Git Enter passphrase for key

当我们配置好ssh key后,发觉每次pull和push都会有如下提示:

ssh-add -k  ~/.ssh/id_rsa      //后面这个是你放置私钥的目录

RPC failed curl 18 transfer closed with outstanding read data fatal protocol error bad pack header

本周从git clone下载项目时由于项目过大,http方式报错protocol error: bad pack header,ssh方式报错fatal: early EOF fatal: index-pack failed期间查阅各种资料,也走了不少弯路,在此整理记录一下,特此分享。

问题描述

git clone用http方式下载报错如下:
1
2
3
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: The remote end hung up unexpectedly
fatal: protocol error: bad pack header
git clone用ssh方式下载报错如下:

SSH公钥配置的也没问题仍然报错

1
2
3
4
5
6
7
8
error: pack-objects died of signal 9/5818)
error: git upload-pack: git-pack-objects died with error.
fatal: git upload-pack: aborting due to possible repository corruption on the remote side.
remote: aborting due to possible repository corruption on the remote side.
fatal: early EOF
fatal: index-pack failed

错误如下图:

在这里插入图片描述

解决方案

第一种方案

网上说http方式报错protocol error: bad pack header需要配置ssh方式即可解决,但是在我的实际操作过程中,ssh方式爆出然报错fatal: early EOF fatal: index-pack failed等错误。

第二种方案

修改本地的git配置:

1
2
3
4
git config –global pack.windowMemory “100m”
git config –global pack.SizeLimit “100m”
git config –global pack.threads “1”
git config –global pack.window “0”

结果未能解决仍然报错。

第三种方案 浅克隆git clone –depth 1 项目地址

可能是下载的项目工程太大导致的,那我们就下载最近的一次commit就好了,即:git clone –depth 1 项目地址,我出现的现象是很快就下载到100%了,但是下载的是一个空文件夹,什么内容都没有,即下载失败

最终解决方案和原因分析

根据这两种错误,我查到的大部分的解决方案就是浅克隆(git clone –depth)、修改git配置:加大缓存区、修改压缩配置等(git config –global),但是未能解决我的问题,最后在一篇博客评论中看到是应该是git服务有问题,不是本地客户端的问题
需要修改git 服务端的配置,进部署git的服务器,不是打开本地命令窗。在git服务器做如下配置即可解决:

1
2
3
4
git config –global pack.windowMemory “100m”
git config –global pack.SizeLimit “100m”
git config –global pack.threads “1”
git config –global pack.window “0”
我的解决方式

将问题交给运维那边处理,运维那边说改配置比较麻烦怕影响其他的(我也没理解),只是简单改了一下,让我在试试浅克隆结果总算成功了如下图:
在这里插入图片描述浅克隆存在的问题:
浅克隆只会把默认分支clone下来,其他远程分支并不在本地,所以这种情况下,需要用如下方法拉取其他分支需要进行如下步骤

1
2
3
4
5
6
7
8
9
10
11
12
13
14
step1:  浅克隆
git clone –depth 1 https://地址/xxxxxxx.git

step2:  cd  到新下载的项目根目录
cd   xxxxxxx

step3: 设置远程要拉取的地址
git remote set-branches origin  分支名称

step4: 浅克隆下载此分支
git fetch –depth 1 origin 分支名称

step5:切换到分支
git checkout 分支名称