我对git很陌生,但我试图用python来检查git存储库是否有任何未提交的更改。无论我尝试使用python运行什么命令,我似乎都会得到相同的错误。这里是我的代码:如何使用Python检查Git Repo是否有未提交的更改
from git import *
repo = Repo("path\to\my\repo")
lastCommit = repo.head.commit.committed_date
uncommitted = repo.is_dirty()
一切正常,直到我跑最后一行是当我得到的错误:
Traceback (most recent call last):
.
.
.
raise GitCommandNotFound: [Error 2] The system cannot find the file specified
我与其他命令试过这也和我一样错误。例如,repo.index.diff(repo.head.commit)
。我也尝试运行repo.index.diff(None)
和repo.index.diff('HEAD')
,它们给出了相同的错误。我真正想要的是为我已命名为repo
的存储库本质上运行$ git status
。我在Windows 7上使用Python 2.7.9和gitpython 1.0.1。任何帮助将不胜感激!
这些“[string lterals](https://en.wikipedia.org/wiki/String_literal)”被称为原始字符串,但请记住,这只是表示程序文本中字符串的一种不同方式 - t表示不同类型的对象。 – holdenweb
@holdenweb感谢您为jtaylor解释。如果在Python 3之前使用'u'而不是'r',那么数据类型将会不同。在Python 3之后,用'b'代替'r'也会改变数据类型。 –