gitpython and git diff

后端 未结 6 1399
终归单人心
终归单人心 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:38

    I am not sure if you got what you were looking for!

    Here is how you do it

    import git
    repo = git.Repo("path/of/repo/")
    
    # the below gives us all commits
    repo.commits()
    
    # take the first and last commit
    
    a_commit = repo.commits()[0]
    b_commit = repo.commits()[1]
    
    # now get the diff
    repo.diff(a_commit,b_commit)
    

    Cheers.

提交回复
热议问题