[Git python API使用标签时返回无效的分支名称

问题描述 投票:1回答:1

我正在尝试使用引用提交的标签签出一个分支。我不断收到错误消息,表示分支名称无效,因为它试图将标记名称作为我分支的一部分。我正在使用仅使用python git api的GitPython

标签名称为v1.1

self.repo.git.checkout("-b test_1.1 v1.1")

这是我遇到的失败:

Traceback (most recent call last):
  File "base.py", line 126, in <module>
    x.checkoutVersion()
  File "base.py", line 118, in checkoutVersion
    self.repo.git.checkout("-b test_1.1 v1.1")
  File "/Library/Python/2.7/site-packages/git/cmd.py", line 545, in <lambda>
    return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
  File "/Library/Python/2.7/site-packages/git/cmd.py", line 1014, in _call_process
    return self.execute(call, **exec_kwargs)
  File "/Library/Python/2.7/site-packages/git/cmd.py", line 825, in execute
    raise GitCommandError(command, status, stderr_value, stdout_value)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
  cmdline: git checkout -b test_1.1 v1.1
  stderr: 'fatal: ' test_1.1 v1.1' is not a valid branch name.'

我可以在终端中很好地运行此命令,我不知道为什么通过API运行该命令失败

我正在使用Python 2.7.10

git python-2.7 git-branch gitpython
1个回答
0
投票

您可以尝试分隔参数,如“ Switching branches”所示:

self.repo.git.checkout('-b', 'test_1.1', 'v1.1')
© www.soinside.com 2019 - 2024. All rights reserved.