Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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找不到提交_Python_Git_Gitpython - Fatal编程技术网

Git Python找不到提交

Git Python找不到提交,python,git,gitpython,Python,Git,Gitpython,我无法通过导航提交树找到标记指向的提交。对于这个特定的示例,我使用的是直接从Github克隆的Tornado Web存储库 import sys import git if len(sys.argv) < 2: print 'python git_test.py <repo path>' sys.exit(0) repo = git.Repo(sys.argv[1]) commits = {} for git_commit in repo.iter_com

我无法通过导航提交树找到标记指向的提交。对于这个特定的示例,我使用的是直接从Github克隆的Tornado Web存储库

import sys
import git

if len(sys.argv) < 2:
    print 'python git_test.py <repo path>'
    sys.exit(0)

repo = git.Repo(sys.argv[1])
commits = {}

for git_commit in repo.iter_commits():
    commits[git_commit.hexsha] = git_commit

print len(commits)

for git_tag in repo.tags:
    print 'Tag %s points to Commit %s' % (
        git_tag.name,
        commits[git_tag.commit.hexsha]
    )
导入系统 进口吉特 如果len(系统argv)<2: 打印“python git_test.py” 系统出口(0) repo=git.repo(sys.argv[1]) 提交={} 对于在repo.iter_commits()中提交的git_: 提交[git_commit.hexsha]=git_commit 打印长度(提交) 对于repo.tags中的git_标签: 打印“标记%s点以提交%s”( git_tag.name, 提交[git_tag.commit.hexsha] ) 这假设可以在git的直接非循环图中找到所有提交,但是,我尝试了另一种方法,通过递归函数递归地导航dag,它提供了相同的结果

ian@ian-EP45-UD3L:~/code/playground$ python git_test.py ~/code/tornado/
459
Tag v1.0.0 points to Commit eb5b3d8df7a305ac1ffa0a12c813e5d7ee4d6cd3
Traceback (most recent call last):
  File "git_test.py", line 19, in <module>
    commits[git_tag.commit.hexsha]
KeyError: '2b5064b7ed962603ade0db0c8e21846a9879e30e'
ian@ian-EP45-UD3L:~/code/playway$python git_test.py~/code/tornado/
459
标记v1.0.0点以提交eb5b3d8df7a305ac1ffa0a12c813e5d7ee4d6cd3
回溯(最近一次呼叫最后一次):
文件“git_test.py”,第19行,在
提交[git_tag.commit.hexsha]
键错误:“2B0064B7ED962603ADE0DB0C8E21846A9879E30E”
如果我做的不对,我如何解决这个问题?感谢您的帮助


我正在使用git python v0.3.1。

我以前没有使用过git python,所以我很好奇,在一个虚拟repo上尝试了您的脚本。我没有得到任何错误和标签打印正确。但我有一个怀疑:

我添加了一个分支,添加了一个提交,并对其进行了标记。然后它给出了你得到的错误,事情变得很明显

repo.iter\u commits()
仅获取当前分支中的提交。因此,在另一个分支中提交的任何标记都不会在
commits
中提交。我尝试将分支更改为我创建的新分支,但它没有指出未找到其他提交,这当然是在我的虚拟repo中的master中

这是你的问题。您需要找到一种从all分支获取所有提交的方法


PS:您知道您正在以一种迂回的方式来获得标记指向右侧的提交吗?

是的,我知道我正在以一种迂回的方式来找到标记点。我的最终目标是创建存储库的可视化。是的,我知道我正在用一种迂回的方法来找到标记点。我的最终目标是创建存储库的可视化。我在分支上循环,然后使用它通过iter_提交(分支)探索图形,但我仍然没有找到一些标记点。所以我找到了一个更好的方法。我创建一个头部点列表,然后使用.parents属性浏览DAG。这些头部点包括通过
repo.tags
获得的标记参考点。这样,如果DAG以某种方式断开连接,我可以找到所有组件。