Get changed files using gitpython

瘦欲@ 提交于 2019-12-03 12:31:12
for item in repo.index.diff(None):
    print item.a_path

or to get just the list:

changedFiles = [ item.a_path for item in repo.index.diff(None) ]

repo.index.diff() returns git.diff.Diffable described in http://gitpython.readthedocs.io/en/stable/reference.html#module-git.diff

So function can look like this:

def get_status(repo, path):
    changed = [ item.a_path for item in repo.index.diff(None) ]
    if path in repo.untracked_files:
        return 'untracked'
    elif path in changed:
        return 'modified'
    else:
        return 'don''t care'
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!