GitPython无法找到头部提交

时间:2018-01-30 01:08:04

标签: git python-3.x gitpython

我想得到我的回购首饰的提交对象。当我尝试拨打repo.head.commit时,我收到以下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python36-32\lib\site-packages\git\refs\symbolic.py", line 200, in _get_commit
    obj = self._get_object()
  File "C:\Python36-32\lib\site-packages\git\refs\symbolic.py", line 193, in _get_object
    return Object.new_from_sha(self.repo, hex_to_bin(self.dereference_recursive(self.repo, self.path)))
  File "C:\Python36-32\lib\site-packages\git\objects\base.py", line 64, in new_from_sha
    oinfo = repo.odb.info(sha1)
  File "C:\Python36-32\lib\site-packages\git\db.py", line 37, in info
    hexsha, typename, size = self._git.get_object_header(bin_to_hex(sha))
  File "C:\Python36-32\lib\site-packages\git\cmd.py", line 1073, in get_object_header
    return self.__get_object_header(cmd, ref)
  File "C:\Python36-32\lib\site-packages\git\cmd.py", line 1062, in __get_object_header
    return self._parse_object_header(cmd.stdout.readline())
  File "C:\Python36-32\lib\site-packages\git\cmd.py", line 1024, in _parse_object_header
    raise ValueError("SHA could not be resolved, git returned: %r" % (header_line.strip()))
ValueError: SHA could not be resolved, git returned: b''

第二次调用repo.head.commit(之后每次),然后我收到以下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python36-32\lib\site-packages\git\refs\symbolic.py", line 200, in _get_commit
    obj = self._get_object()
  File "C:\Python36-32\lib\site-packages\git\refs\symbolic.py", line 193, in _get_object
    return Object.new_from_sha(self.repo, hex_to_bin(self.dereference_recursive(self.repo, self.path)))
  File "C:\Python36-32\lib\site-packages\git\objects\base.py", line 64, in new_from_sha
    oinfo = repo.odb.info(sha1)
  File "C:\Python36-32\lib\site-packages\git\db.py", line 37, in info
    hexsha, typename, size = self._git.get_object_header(bin_to_hex(sha))
  File "C:\Python36-32\lib\site-packages\git\cmd.py", line 1073, in get_object_header
    return self.__get_object_header(cmd, ref)
  File "C:\Python36-32\lib\site-packages\git\cmd.py", line 1061, in __get_object_header
    cmd.stdin.flush()

其他信息: repo.head - &gt; <git.HEAD "HEAD">

我在Windows 10环境中。这可能与我的另一个问题有关: Git Not Working with Ubuntu -> Windows Samba Shared Directory

2 个答案:

答案 0 :(得分:2)

像这样初始化repo对象对我有用:

import git

repo = git.Repo('.', odbt=git.db.GitDB)

虽然此解决方案似乎有些警告。可以在here中找到更多详细信息。

答案 1 :(得分:0)

问题是由于我的目录位于UNC路径上,并通过更新我的git版本来修复。

Git not working with Ubuntu → Windows Samba shared directory