简体   繁体   English

GitPython-无法获取回购索引?

[英]GitPython - cannot get index for repo?

How on earth does one get the index for a repos using GitPython ? 到底如何使用GitPython获取仓库的索引?

import git

repo = git.Repo.init('/path/to/repos/')
... add some files ...
... commit ...
index = repo.index()

Throw error: 'Repo' object has no attribute 'index' 引发错误:“回购”对象没有属性“索引”

WTH? WTH? My eyes are bloody from reading the Trier tutorial over and over getting nowhere fast. 一遍又一遍地阅读特里尔教程,我的眼睛很血腥。 Clues anyone ? 线索有人吗?

There are two issues here. 这里有两个问题。 First, index isn't method, it's an IndexFile object. 首先, index不是方法,它是一个IndexFile对象。 Secondly, I wonder if you're not using the current version of GitPython. 其次,我想知道您是否没有使用当前版本的GitPython。

If I start with: 如果我以:

$ virtualenv stacktest
$ ./stacktext/bin/pip install GitPython
$ ./stackext/bin/python
Python 2.7.5 (default, Nov 12 2013, 16:18:42) 
[GCC 4.8.2 20131017 (Red Hat 4.8.2-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import git
>>> repo = git.Repo.init('/home/username/projects/myproject')
>>> repo.index
<git.index.base.IndexFile object at 0x1213a48>
>>> repo.index.entries
{('README.md', 0): (100644, 515cbd1e78aa13ec91941eaa63ecec89d5e4b947, 0, README.md), ('setup.py', 0): (100644, 7497e295447af70a6865b7313bfb2f86ba6577d6, 0, setup.py)}

Another possibility is that something in your code is masking the attribute. 另一种可能性是代码中的某些内容掩盖了属性。 If you can post an actual runnable code sampe that someone else can run, that will help narrow down the problem. 如果您可以发布其他人可以运行的实际可运行代码示例,则将有助于缩小问题的范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM