0

GitPython を使用して新しいローカル リポジトリを初期化し、最初のコミットを作成して正規のリポジトリにプッシュします。残念ながら、最後のステップが失敗しており、その理由を理解するのに非常に苦労しています。変数を間違って使用しているだけだと確信していGIT_SSH_COMMANDますが、その方法がわかりません。続く例はあまりありません。

私はこのSOの質問を読み、関連する問題を掘り下げてコミットしましたが、明らかにそれを正しくまとめることができませんでした。

ヘルプ?

Git v2.3+​​の「証明」

$ git --version                                                                                                                          
git version 2.3.1

スクリプト スニペット

# Please take my word that I've init'd the repo and that any variables
# have been defined and initialized.
git_ssh_identity_file = os.path.expanduser('~/.ssh/id_rsa')
git_ssh_cmd = 'ssh -i %s' % git_ssh_identity_file
with git_project.git.custom_environment(GIT_SSH_COMMAND=git_ssh_cmd):
    git_project.remotes.origin.push(git_project.heads.master)

結果のエラー

Traceback (most recent call last):
  File "./ct-new-project.py", line 204, in <module>
    git_project.remotes.origin.push(git_project.heads.master)
  File "/Library/Python/2.7/site-packages/git/remote.py", line 667, in push
    return self._get_push_info(proc, progress or RemoteProgress())
  File "/Library/Python/2.7/site-packages/git/remote.py", line 588, in _get_push_info
    handle_process_output(proc, stdout_handler, progress_handler, finalize_process)
  File "/Library/Python/2.7/site-packages/git/cmd.py", line 202, in handle_process_output
    return finalizer(process)
  File "/Library/Python/2.7/site-packages/git/util.py", line 158, in finalize_process
    proc.wait()
  File "/Library/Python/2.7/site-packages/git/cmd.py", line 300, in wait
    raise GitCommandError(self.args, status, self.proc.stderr.read())
git.exc.GitCommandError: 'git push --porcelain origin master' returned with exit code 128
4

1 に答える 1

1

GitPython がこの種のエラーをスローした場合、実行しようとしている実際のコマンドがコマンド ラインから機能することを常に確認する価値があります。コマンドの正常な完了を妨げる何かがローカル クローンで変更された可能性があります。

GitPython で達成しようとしているものと同等のことは、次の方法で実行できます。

$ GIT_SSH_COMMAND='ssh -i ~/.ssh/id_rsa' git push --porcelain origin master

少なくともLINUXでは。Windows では、おそらく別のコマンドで環境変数を直接設定する必要があります。

このような実験をするとき、ハードドライブのどこかにプッシュできる「ローカル」アップストリームがあると便利だと思います。これにより、それを破棄して再起動できgit push --forceます。または、アップストリームの 2 番目の (元の) クローンから..少なくとも一度は台無しにすることを知っておいてください。

于 2015-03-02T18:07:28.707 に答える