【问题标题】:How to check if a Git Repo has uncommitted changes by gitpython如何通过 gitpython 检查 Git Repo 是否有未提交的更改
【发布时间】:2015-12-26 22:18:43
【问题描述】:

我试过了

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

但是得到了:

git.exc.GitCommandNotFound: [错误 2]

这是一个错误吗?

【问题讨论】:

  • 你使用的是哪个版本的 git 和 gitpython?

标签: python git gitpython


【解决方案1】:

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

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

来自exc.py 中的gitpython

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

您还可以直接从 python 以独立于平台的方式设置环境变量,如这里详细描述的那样,而不是修改您的启动脚本(又名 ~/.bash_profile 或类似的):

Python: Platform independent way to modify PATH environment variable

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-16
    • 2017-08-26
    • 1970-01-01
    • 2015-10-15
    • 1970-01-01
    • 1970-01-01
    • 2011-08-25
    • 1970-01-01
    相关资源
    最近更新 更多