git error

starlitxiling Lv3

记录一次git push大仓库的问题,背景是一个在本地的仓库推送到一个新仓库中(包括所有的历史提交记录)

git error: failed to push some refs to remote

这个问题是本地和远程会产生冲突,因为远程是新仓库,和本地仓库并没有联系,所以这里可以直接git pull <repository> <branch> --allow-unrelated-histories

error: RPC failed; HTTP 500 curl 22 The requested URL returned error: 500

这个错误大家可能认为是网络的问题,但是我在推送的时候发现每次都是在2.43GB的时候git就会退出报出这个错误,后面查阅之后发现是Github对单次push的大小有限制,最大为2GB,具体的情况可以看Troubleshoting the 2GB push limit ,这里我写了一个bash脚本,它能够自动一点点推送你的仓库,如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash

# set remote repository and branch
remote="rustlinux"
branch="rust"

# set the number of commits to push per batch
batch_size=5000

# the hash value provided by the user is pushed
# start_commit_hash=$1

# if [ -z "$start_commit_hash" ]; then
# echo "No start commit hash provided. Exiting..."
# exit 1
# fi

# get hashed of all commits(oldest to newest)
commit_hashes=$(git rev-list --reverse HEAD)
# commit_hashes=$(git rev-list --reverse $start_commit_hash..HEAD)

# read the hash value into an array
commit_array=($commit_hashes)

# calculate the total number of submissions
total_commits=${#commit_array[@]}

# push in batches
for (( i=0; i<total_commits; i+=batch_size ))
do
end_index=$((i + batch_size - 1))

# check if it exceeds the array range
if [ $end_index -ge $total_commits ]; then
end_index=$((total_commits - 1))
fi

# get the hash value of the last submission of the current batch
end_commit_hash=${commit_array[$end_index]}

echo "Pushing from commit $i to $end_index: $end_commit_hash"

# push the current batch
git push $remote $end_commit_hash:$branch --force

# check if the push is successful
if [ $? -ne 0 ]; then
echo "Error pushing to $remote. Stopping the script."
exit 1
fi

echo "Successfully pushed to $remote up to commit $end_commit_hash"
done

echo "All commits have been successfully pushed."

这里额外提供了一个在运行脚本时候接收参数的功能,可以让你手动停下脚本后还可以继续从上次没有推送的hash值继续开始推送(这里要给的是上次推送时最后一次成功的hash值,而不是手动停止的那一次)

git功能

git gc:用于优化仓库的性能和减少磁盘使用空间。

git fsck:用于验证Git仓库中所有对象的完整性和连接性,一般在git gc后使用

git config --global http.postBuffer 157286400: 这个是增加你的git buffer,这样可以推送更大文件。

  • Title: git error
  • Author: starlitxiling
  • Created at : 2024-07-16 09:55:41
  • Updated at : 2024-09-14 22:05:35
  • Link: http://starlitxiling.github.io/2024/07/16/error/
  • License: This work is licensed under CC BY-NC-SA 4.0.
Comments