【问题标题】:Python GIT CHeckout failed due to: exit code(1)Python GIT 检查失败,原因是:退出代码 (1)
【发布时间】:2021-10-16 10:31:09
【问题描述】:

我在 gitlab 中有一个 git repo。我尝试使用以下几行检查 master 分支。

repo = git.Repo(os.path.dirname(__file__), search_parent_directories=True)
repo.git.checkout("master")
ref_repo_root = os.path.join(WORKING_DIRECTORY, 'ref_decoders')

但我收到以下错误。

E   git.exc.GitCommandError: Cmd('git') failed due to: exit code(1)
E     cmdline: git checkout master
E     stderr: 'error: pathspec 'master' did not match any file(s) known to git.'

我知道 repo.git.checkout("HEAD~1") 工作正常。我的问题在哪里?

【问题讨论】:

  • 实际上是否有一个名为master 的分支?这不再完全得到保证 - 出于政治原因,一些托管服务会安排事情(或为您提供安排事情的设置步骤)以将主分支命名为其他名称。
  • 明确一点,你是在使用this package 与git 交互吗?还是别的什么?
  • 你好 Karl,我使用以下 python-git 包。
  • 仓库有哪些分支?运行git branch -a
  • 这个存储库有一个 master 和其他分支。我试图检查所有这些分支。但问题是一样的。它适用于 Head~1

标签: python git gitlab checkout master


【解决方案1】:

从 v14.0 开始,gitlab 中的默认分支是 main 而不是 master。 阅读此处了解更多信息:https://about.gitlab.com/blog/2021/03/10/new-git-default-branch-name/

【讨论】:

  • 您好,感谢您的提示。但我遇到了同样的问题。 E git.exc.GitCommandError: Cmd('git') failed due to: exit code(1) E cmdline: git checkout main E stderr: 'error: pathspec 'main' 与 git 已知的任何文件都不匹配。 '
  • master/main 分支是否存在?
  • 嗨,Gabip,主人确实存在。
  • 您提到repo.git.checkout("HEAD~1") 有效。 git 认为你目前在哪个分支(git status 中说什么)?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-05-19
  • 1970-01-01
  • 2016-04-18
  • 2017-07-14
  • 2018-04-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多