如何通过gitpython检查Git Repo是否有未提交的更改

时间:2015-09-29 12:21:06

标签: python git gitpython

我试过

g = git.Repo(r'C:\Users\Administrator\Desktop\testRepo')
print g.untracked_files

但得到了:

  

git.exc.GitCommandNotFound:[错误2]

这是一个错误吗?

1 个答案:

答案 0 :(得分:5)

当我做同样的事情时,我没有这个错误。

您的$ {PATH}变量中是否有git个可执行文件? 如果你使用bash,你可以运行 export PATH=$PATH:/path/to/your/git/executable

来自exc.py中的gitpython

class GitCommandNotFound(Exception): """Thrown if we cannot find the的git executable in the PATH or at the path given by the GIT_PYTHON_GIT_EXECUTABLE environment variable""" pass 可以假设设置env变量也可能有帮助。

您也可以直接从python中以与平台无关的方式设置env变量,如此处所述,而不是修改您的启动脚本(也就是〜/ .bash_profile或类似):

Python: Platform independent way to modify PATH environment variable

相关问题