[英]How to check if a Git Repo has uncommitted changes by gitpython
I tried我试过
g = git.Repo(r'C:\Users\Administrator\Desktop\testRepo')
print g.untracked_files
But got:但得到:
git.exc.GitCommandNotFound: [Error 2]
git.exc.GitCommandNotFound: [错误 2]
Is it a bug?这是一个错误吗?
I don't have this error when I do exactly the same.当我做完全相同的事情时,我没有这个错误。
Do you have git
executable in your ${PATH} variable?你的 ${PATH} 变量中有
git
可执行文件吗? If you are using bash you can run export PATH=$PATH:/path/to/your/git/executable
如果你使用 bash 你可以运行
export PATH=$PATH:/path/to/your/git/executable
From exc.py
in gitpython
:来自
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
one can assume that setting that env variable may also help. class GitCommandNotFound(Exception): """Thrown if we cannot find the
executable in the PATH or at the path given by the GIT_PYTHON_GIT_EXECUTABLE environment variable""" pass
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
class GitCommandNotFound(Exception): """Thrown if we cannot find the
executable in the PATH or at the path given by the GIT_PYTHON_GIT_EXECUTABLE environment variable""" pass
可以假设设置该 env 变量也可能有帮助。
You can also set env variable directly from python in platform-independent way as greatly described here, instead of modifying your startup script (aka ~/.bash_profile or similar ):您还可以直接从 python 以平台无关的方式设置 env 变量,如这里所描述的那样,而不是修改您的启动脚本(又名 ~/.bash_profile 或类似的):
Python: Platform independent way to modify PATH environment variable Python:独立于平台的方式来修改 PATH 环境变量
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.