【问题标题】:How to print the contents of a pygit object in python如何在 python 中打印 pygit 对象的内容
【发布时间】:2015-02-03 16:17:40
【问题描述】:

我正在尝试打印“diff”对象,如下所示。我期待类似于 git show 的输出,但我没有得到相同的结果。我如何实现这一目标?谢谢。

import pygit2
repo=pygit2.Repository('/home/repository')

t0=repo.revparse_single('HEAD')
t1=repo.revparse_single('HEAD^')


>>> repo.diff(t0,t1)
<_pygit2.Diff object at 0x7fc46eeb0470>
>>> out=repo.diff(t0,t1)
>>> print out
<_pygit2.Diff object at 0x7fc46eeb0410>
>>> 

【问题讨论】:

    标签: python git pygit2


    【解决方案1】:

    让我们查看pygit2 的文档:

    $ pydoc pygit2.Diff
     |  ----------------------------------
     |  Data descriptors defined here:
     |  
     |  patch
     |      Patch diff string.
    

    好的,让我们试试吧:

    >>> out=repo.diff(t0,t1)
    >>> print out
    <_pygit2.Diff object at 0x7fc46eeb0410>
    >>> print out.patch
    diff --git a/file1 b/file1
    index 10952f3..66ed2b8 100644
    --- a/file1
    +++ b/file1
    @@ -1,5 +1,6 @@
     DIR_COLORS
     DIR_COLORS.256color
    +DIR_COLORS.lightbgcolor
     GREP_COLORS
     X11
     adjtime
    

    似乎有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-04
      • 2015-01-21
      • 2016-02-17
      • 2018-10-03
      • 1970-01-01
      • 1970-01-01
      • 2020-02-05
      • 2019-11-19
      相关资源
      最近更新 更多