Как установить максимальное количество фиксации на git push

Я нахожусь в процессе миграции существующего репозитория SVN (только магистраль) с более чем 10000 фиксаций к размещенному решению 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 коммитов, которых еще нет на сервере?

Я не хочу указывать каждый коммит для push (как в этом вопросе ответил ). Я просто хочу установить максимальное количество.

1 ответ

  1. Я описал ручной способ сделать это в моем ответе на «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=
    	

    I described the manual way to do this in my answer to "Git error: RPC failed; result=22, HTTP code = 404". (That answer also describes what to do if you get stuck on one large commit.)

    As I mentioned in that answer and in the comments, I recommend switching from HTTPS to SSH if you can, because I haven't had this kind of problem with pushing with SSH; it seems to be limited to HTTPS.

    However, if you're stuck on HTTPS, you'll have to push a smaller subset of commits at a time. As requested in your question, here's a way to automate the process (in the form of a script that I threw together):

    #!/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
    

    I don't have a repo/server handy to test this on, but it should at least get you started.

    Note that this doesn't limit the commits to a certain number, but does a binary search to figure out how many commits can be successfully pushed at once.

    For completeness, here's a script that pushes a specific number of commits at a time:

    #!/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
    

    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

    У меня нет под рукой repo/server, чтобы проверить это, но это должно, по крайней мере, начать.

    Обратите внимание, что это не ограничивает коммиты определенным числом, но выполняет двоичный поиск, чтобы выяснить, сколько коммитов может быть успешно перемещено сразу.

    Для полноты, вот сценарий, который толкает определенное количество коммитов одновременно:

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

    I described the manual way to do this in my answer to "Git error: RPC failed; result=22, HTTP code = 404". (That answer also describes what to do if you get stuck on one large commit.)

    As I mentioned in that answer and in the comments, I recommend switching from HTTPS to SSH if you can, because I haven't had this kind of problem with pushing with SSH; it seems to be limited to HTTPS.

    However, if you're stuck on HTTPS, you'll have to push a smaller subset of commits at a time. As requested in your question, here's a way to automate the process (in the form of a script that I threw together):

    #!/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
    

    I don't have a repo/server handy to test this on, but it should at least get you started.

    Note that this doesn't limit the commits to a certain number, but does a binary search to figure out how many commits can be successfully pushed at once.

    For completeness, here's a script that pushes a specific number of commits at a time:

    #!/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
    

    atonce=
    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