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

前端 未结 5 1155
故里飘歌
故里飘歌 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条回答
  •  無奈伤痛
    2021-01-14 05:40

    For a proper solution (without using git command callback), you have to use create_patch option.

    To compare current index with previous commit:

    diff_as_patch = repo.index.diff(repo.commit('HEAD~1'), create_patch=True)
    print(diff_as_patch)
    

提交回复
热议问题