我對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'也會改變數據類型。 –