GitPython Unable to Find Head Commit

佐手、 提交于 2019-12-13 03:39:58

问题


I want to get the commit object of my repo's HEAD. When I try to call repo.head.commit however, I get the following error:

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''

Calling repo.head.commit a second time (and every time afterwards), I then get the following error:

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()

Additional Information: repo.head -> <git.HEAD "HEAD">

I'm on a Windows 10 environment. This may be related to another question of mine: Git Not Working with Ubuntu -> Windows Samba Shared Directory


回答1:


The problem was arising from my directory being located on a UNC path and was fixed by updating my git version.

Git not working with Ubuntu → Windows Samba shared directory



来源:https://stackoverflow.com/questions/48512409/gitpython-unable-to-find-head-commit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!