如何在git push上设置最大提交次数

时间:2016-10-06 10:04:33

标签: git git-svn git-push

我正在将一个拥有超过10000次提交的现有SVN存储库(只有主干)迁移到托管的Git解决方案(在我的案例中为BitBucket)。

将SVN repo转换为本地Git没有问题,但现在我想将所有修订版推送到一个空的Git仓库在线。

但是从TortoiseGit做推动,它会停止输出:

git.exe push -v --progress "origin" master

Counting objects: 198817, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (83858/83858), done.
POST git-receive-pack (chunked)
Writing objects: 100% (198817/198817), 1.54 GiB | 460.00 KiB/s, done.
Total 198817 (delta 130510), reused 178506 (delta 112822)
fatal: The remote end hung up unexpectedly
fatal: The remote end hung up unexpectedly
error: RPC failed; curl 52 Empty reply from server
Pushing to https://__removed__@bitbucket.org/__removed__/__removed__.git
Everything up-to-date


git did not exit cleanly (exit code 1) (3644609 ms @ 06.10.2016 11:16:23)

我认为我问题的唯一解决方案是一次只能推送1000次提交。但是,如何限制服务器上尚未提交的前1000次提交?

我不想指定每个提交提交(如在this question answered中)。我只是想设置一个最大数量。

1 个答案:

答案 0 :(得分:0)

我在my answer to "Git error: RPC failed; result=22, HTTP code = 404"中描述了手动方式。 (该答案还描述了如果您遇到一次大型提交该怎么办。)

正如我在答案和评论中提到的,如果可以的话,我建议从HTTPS切换到SSH,因为我没有使用SSH推送这种问题;它似乎仅限于HTTPS。

但是,如果您坚持使用HTTPS,则必须一次推送较小的提交子集。根据你的问题的要求,这里有一种自动化过程的方式(以我整合的脚本的形式):

#!/bin/bash
# Bisect a git push to get around HTTP POST size limits.

branch=$1
commits=$(git log --oneline | wc -l)
current=$commits

while [ $(git rev-parse origin/$branch 2>/dev/null) != $(git rev-parse $branch) ]
do
  # Git push command counts backwards, so invert the counter.
  inverse=$(expr $commits - $current)
  git push origin $branch~$inverse:$branch

  if [ $? -ne 0 ]
  then
    # If failed, bisect further, if possible.
    if [ $current > 1]
    then
      current=$(expr $current / 2)
    else
      echo "Error, could not push single commit."
      exit 1
    fi
  else
    # If successful, reset bisect.
    current=$commits
  fi
done

我没有备用/服务器来测试它,但它至少应该让你开始。

请注意,这并不会将提交限制为某个数字,而是进行二进制搜索以确定可以一次成功推送多少次提交。

为了完整性,这里是一个脚本,一次推送特定数量的提交:

#!/bin/bash
# Push commits in smaller batches.

branch=$1
atonce=$2
commits=$(git log --oneline | wc -l)
current=$atonce

while [ $(git rev-parse origin/$branch 2>/dev/null) != $(git rev-parse $branch) ]
do
  # Git push command counts backwards, so invert the counter.
  inverse=$(expr $commits - $current)
  git push origin $branch~$inverse:$branch

  if [ $? -ne 0 ]
  then
    echo "Error, could not push $atonce commits."
    exit 1
  else
    current=$(expr $commits + $atonce)
  fi
done
相关问题