如何使用gitpython与当前提交进行当前提交的git diff? [英] how to do a git diff of current commit with last commit using gitpython?
本文介绍了如何使用gitpython与当前提交进行当前提交的git diff?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试掌握gitpython模块,
I am trying o grasp gitpython module,
hcommit = repo.head.commit
tdiff = hcommit.diff('HEAD~1')
但是tdiff = hcommit.diff('HEAD^ HEAD')
不起作用! ('HEAD~ HEAD')
.,
我正在尝试获取差异输出!
I am trying to get the diff output !
推荐答案
我想出了如何使用gitPython获取git diff.
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 !!!
Voila !!!
这篇关于如何使用gitpython与当前提交进行当前提交的git diff?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文