我正在尝试掌握 gitpython 模块,
hcommit = repo.head.commit
tdiff = hcommit.diff('HEAD~1')
but tdiff = hcommit.diff('HEAD^ HEAD')
不起作用!也不('HEAD~ HEAD')
.,
我正在尝试获取差异输出!
import git
repo = git.Repo('repo_path')
commits_list = list(repo.iter_commits())
# --- To compare the current HEAD against the bare init commit
a_commit = commits_list[0]
b_commit = commits_list[-1]
a_commit.diff(b_commit)
这将为提交返回一个 diff 对象。还有其他方法可以实现这一目标。例如(这是从复制/粘贴http://gitpython.readthedocs.io/en/stable/tutorial.html#obtaining-diff-information):
```
hcommit = repo.head.commit
hcommit.diff() # diff tree against index
hcommit.diff('HEAD~1') # diff tree against previous tree
hcommit.diff(None) # diff tree against working tree
index = repo.index
index.diff() # diff index against itself yielding empty diff
index.diff(None) # diff index against working copy
index.diff('HEAD') # diff index against current HEAD tree
```
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)