gitpython and git diff

后端 未结 6 1381
终归单人心
终归单人心 2021-02-12 21:48

I am looking to get only the diff of a file changed from a git repo. Right now, I am using gitpython to actually get the commit objects and the files of git changes, but I want

6条回答
  •  温柔的废话
    2021-02-12 22:42

    I'd suggest you to use PyDriller instead (it uses GitPython internally). Much easier to use:

    for commit in RepositoryMining("path_to_repo").traverse_commits():
        for modified_file in commit.modifications: # here you have the list of modified files
            print(modified_file.diff)
            # etc...
    

    You can also analyze a single commit by doing:

    for commit in RepositoryMining("path_to_repo", single="123213")
    

提交回复
热议问题