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

Lou*_*uYu 1 python git gitpython

我试过了

g = git.Repo(r'C:\Users\Administrator\Desktop\testRepo')
print g.untracked_files
Run Code Online (Sandbox Code Playgroud)

但得到了:

git.exc.GitCommandNotFound:[错误2]

这是一个错误吗?

Zlo*_*loj 5

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

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

exc.pygitpython:

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

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

Python:独立于平台的修改PATH环境变量的方法