Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.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
在git python中通过hexsha获取提交对象_Python_Git_Gitpython - Fatal编程技术网

在git python中通过hexsha获取提交对象

在git python中通过hexsha获取提交对象,python,git,gitpython,Python,Git,Gitpython,我正在尝试查找在两个特定提交之间签入的提交内容 在git中,我要做git版本列表--祖先路径.. 在git python中,由于看起来没有直接的方法,所以我求助于调用确切的命令,通过repo.git.execute()。 输出是一个提交ID字符串(十六进制SHA) 现在,在git python中有没有一种方法可以创建一个有效的Commit对象,从execute()给出的十六进制SHA开始?经过多次的探索,鉴于这个问题没有得到太多的关注,我求助于使用.execute()。 具体而言: commit

我正在尝试查找在两个特定提交之间签入的提交内容

在git中,我要做
git版本列表--祖先路径..

在git python中,由于看起来没有直接的方法,所以我求助于调用确切的命令,通过
repo.git.execute()
。 输出是一个提交ID字符串(十六进制SHA)


现在,在git python中有没有一种方法可以创建一个有效的
Commit
对象,从
execute()
给出的十六进制SHA开始?

经过多次的探索,鉴于这个问题没有得到太多的关注,我求助于使用
.execute()
。 具体而言:

commits = repo.git.execute(['git', 'rev-list', '--ancestry-path',
                            '%s..%s' % (oldCommit.hexsha, newCommit.hexsha)]).split()

当然,
oldCommit
newCommit
都是
git.Commit
对象。

我在git python中没有找到通过sha获取特定提交对象的函数。 因此,我只能考虑通过所有的承诺来实现:

def get_commit_by_sha(repo,sha):
对于r.iter_提交()中的c:
如果c.hexsha==最后一个:
返回c
一无所获
至于比较两次提交之间的差异,请参见具体提交。
diff
方法很有用,一个简单的用法:

old_commit.diff(new_commit.hexsha)

结果是一个
git.diff.DiffIndex
对象,请参阅

您可以使用Repo.commit方法通过sha获取特定的提交对象。只需将sha字符串作为
rev
参数传递。例如:
repo.commit('8556c92f96022162da21684194febfa617ead5e1')