Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中构造git diff查询_Python_Git - Fatal编程技术网

如何在python中构造git diff查询

如何在python中构造git diff查询,python,git,Python,Git,我用的是推荐的, 但我不知道如何构造以下命令: git diff --name-status ec04352 b945e6c 我想获得关于两次提交之间所有修改文件的信息,这个命令正是我想要做的。您能对此发表评论吗?请参阅GitPython手册中的一些示例,了解如何获取两次提交之间的差异信息 hcommit = repo.head.commit idiff = hcommit.diff() # diff tree against index tdiff = hcommit.d

我用的是推荐的, 但我不知道如何构造以下命令:

git diff --name-status ec04352 b945e6c 
我想获得关于两次提交之间所有修改文件的信息,这个命令正是我想要做的。您能对此发表评论吗?

请参阅GitPython手册中的一些示例,了解如何获取两次提交之间的差异信息

hcommit = repo.head.commit
idiff = hcommit.diff()          # diff tree against index
tdiff = hcommit.diff('HEAD~1')  # diff tree against previous tree
wdiff = hcommit.diff(None)      # diff tree against working tree
这些命令返回a,其中包含
iter\u change\u type
,您可以使用四种不同的更改类型(
'a','D','R','M'
)中的每一种调用该类型,以获取已更改(添加、删除、重命名、修改)的路径.

有关如何获取两次提交之间的差异信息的一些示例,请参见GitPython手册中的

hcommit = repo.head.commit
idiff = hcommit.diff()          # diff tree against index
tdiff = hcommit.diff('HEAD~1')  # diff tree against previous tree
wdiff = hcommit.diff(None)      # diff tree against working tree

这些命令返回a,其中包含
iter\u change\u type
,您可以使用四种不同的更改类型(
'a','D','R','M'
)中的每一种调用该类型,以获取已更改(添加、删除、重命名、修改)的路径。

这是一种方法:

import git

repo = git.Repo('path/to/your/repo')
print repo.git.diff('ec04352', 'b945e6c', **{'name-status': True})
然而,它正在走后门

您应该能够执行以下操作:

a = repo.commit('ec04352')
b = repo.commit('b945e6c')
diffs = a.diff(b)

>>> a
<git.Commit "ec04352">
>>> b
<git.Commit "b945e6c">
>>> print diffs[0]
zip/JSONzip.java
=======================================================
lhs: 100644 | d8e3ac652a5a5158692fa5fc131340c03dffd08e
rhs: 100644 | 220686de3dcb0dd17a54cbc5f8e44df261b664d5
>>> 
a=repo.commit('ec04352')
b=回购提交('b945e6c')
差异=a.diff(b)
>>>a
>>>b
>>>打印差异[0]
zip/JSONzip.java
=======================================================
lhs:100644 | D8E3AC652A5158692FA5FC131340C03DFFD08E
rhs:100644 | 220686de3dcb0dd17a54cbc5f8e44df261b664d5
>>> 

您需要使用
Diff
对象来找出差异。

这是一种方法:

import git

repo = git.Repo('path/to/your/repo')
print repo.git.diff('ec04352', 'b945e6c', **{'name-status': True})
然而,它正在走后门

您应该能够执行以下操作:

a = repo.commit('ec04352')
b = repo.commit('b945e6c')
diffs = a.diff(b)

>>> a
<git.Commit "ec04352">
>>> b
<git.Commit "b945e6c">
>>> print diffs[0]
zip/JSONzip.java
=======================================================
lhs: 100644 | d8e3ac652a5a5158692fa5fc131340c03dffd08e
rhs: 100644 | 220686de3dcb0dd17a54cbc5f8e44df261b664d5
>>> 
a=repo.commit('ec04352')
b=回购提交('b945e6c')
差异=a.diff(b)
>>>a
>>>b
>>>打印差异[0]
zip/JSONzip.java
=======================================================
lhs:100644 | D8E3AC652A5158692FA5FC131340C03DFFD08E
rhs:100644 | 220686de3dcb0dd17a54cbc5f8e44df261b664d5
>>> 
您需要使用
Diff
对象来找出差异