how to do a git diff of current commit with last commit using gitpython?

前端 未结 5 1159
故里飘歌
故里飘歌 2021-01-14 05:12

I am trying o grasp gitpython module,

hcommit = repo.head.commit
tdiff = hcommit.diff(\'HEAD~1\')

but tdiff = hcommit.diff(\'HEAD^ H

5条回答
  •  Happy的楠姐
    2021-01-14 05:37

    I figured out how to get the git diff using gitPython.

    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)
    

    Voila !!!

提交回复
热议问题