2017-02-22 149 views
1

我正在尝试使用gitpython,而我对它很陌生。我正在尝试检测是否有任何更改进行提交。gitpython检查使用PYTHON的文件是否有任何更改

目前,我有一个功能,看起来像这样:

def commit(dir): 
r = Repo(dir) 
r.git.add(A=True) 
r.git.commit(m='commit all') 

但这只是犯目录中的代码。我想要做些什么,如果有变化,然后显示一些消息,否则,显示另一条消息。

任何人有任何想法我如何在Python中做到这一点?

回答

0

您可以检查所有类似的未分级的变化:

for x in r.index.diff("HEAD"): 
    # Just print 
    print x 

    # Or for each entry you can find out information about it, e.g. 
    print x.new_file 
    print x.b_path 

基本上你是比较临时区域(即index)到活动的分支。