【问题标题】:How to set a maximum commit count on git push如何在 git push 上设置最大提交计数
【发布时间】:2017-02-15 00:40:23
【问题描述】:

我正在将具有超过 10000 次提交的现有 SVN 存储库(仅主干)迁移到托管 Git 解决方案(在我的情况下为 BitBucket)。

将 SVN 存储库转换为本地 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 中)。我只是想设置一个最大计数。

【问题讨论】:

  • “我认为我的问题的唯一解决方案是一次只推送 1000 个提交” - 你为什么这么认为?
  • 我认为我的推动力太大了。我想尝试将其缓冲为较小的部分。
  • 我不太确定问题出在哪里,但它很容易测试:在master 上的一长串提交开始附近选择一个提交,然后手动推送那个(这当然也会推动它的祖先提交),git push <remote> <hashid>:master。如何从一些烦人的 GUI 中做到这一点(与烦人的命令行相比 :-)),我不知道。
  • 你能从 HTTPS 切换到 SSH 吗?

标签: git git-svn git-push


【解决方案1】:

我在my answer to "Git error: RPC failed; result=22, HTTP code = 404" 中描述了执行此操作的手动方式。 (该答案还描述了如果您卡在一个大型提交上该怎么办。)

正如我在那个答案和 cmets 中提到的,如果可以的话,我建议从 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

【讨论】:

  • 第二个版本的最后一个expr应该是$current + $atonce吗?
猜你喜欢
  • 2021-11-19
  • 2014-02-22
  • 2011-04-22
  • 2011-07-28
  • 2015-09-25
  • 2017-10-04
  • 1970-01-01
  • 2020-08-20
  • 1970-01-01
相关资源
最近更新 更多