使用GitPython,我可以使用以下内容创建一个新的存储库:
from git.repo.base import Repo
Repo.init('/tmp/some-repo/')
该存储库是使用默认分支创建的master。
如何修改这个默认分支?
更新:正如下面的答案中所建议的,我尝试使用Repo.init('/tmp/some-repo', initial_branch="main"),但是它呈现了此异常:
Traceback (most recent call last):
File "/app/checker/tests.py", line 280, in test_alternative_compare_branch
comp_repo_main = Repo.init(
File "/usr/local/lib/python3.9/site-packages/git/repo/base.py", line 937, in init
git.init(**kwargs)
File "/usr/local/lib/python3.9/site-packages/git/cmd.py", line 542, in <lambda>
return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/git/cmd.py", line 1005, in _call_process
return self.execute(call, **exec_kwargs)
File "/usr/local/lib/python3.9/site-packages/git/cmd.py", line 822, in execute
raise GitCommandError(command, status, stderr_value, stdout_value)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(129)
cmdline: git init --initial-branch=main
stderr: 'error: unknown option `initial-branch=main'
在 git 文档中,它指出设置初始分支的命令是--initial-branch(https://git-scm.com/docs/git-init/2.28.0#Documentation/git-init.txt---initial-branchltbranch-名称gt)。
从错误来看,我认为 GitPython 的附加 kwargs 功能不包括前缀--。
潇潇雨雨
相关分类