1

我是 PythonGit 的新手,拉和推有问题。我在本地创建了裸仓库并将初始提交推送给它。之后,我尝试使用 PythonGit 初始化新用户 repo,获取并从中提取。我对初始化存储库没有任何问题,但是我无法从远程/裸存储库中获得任何东西。我的代码:

import git

repo = git.Repo.init('.')
origin = repo.create_remote('origin', '/home/paweber/git/my-repo.git')
origin.fetch()            
repo.create_head('master', origin.refs.master).set_tracking_branch(origin.refs.master)
origin.pull()

在用于获取和拉取的 ipython 控制台中,我得到:

In [5]: origin.fetch()
Out[5]: [<git.remote.FetchInfo at 0x7f4a4d6ee630>]

用于获取和

In [6]: origin.pull()
Out[6]: [<git.remote.FetchInfo at 0x7f4a4d6e6ee8>]

拉。拉动操作后,根本没有拉动任何东西,回购仍然是空的,但存在。我做错了什么?

4

2 回答 2

2

pull()不做任何事情,因为master它已经在它的目标提交处,由 . 指向的那个origin/master

此代码将按预期工作:

import git

repo = git.Repo.init('.')
origin = repo.create_remote('origin', '/home/paweber/git/my-repo.git')
origin.fetch()
# the HEAD ref usually points to master, which is 'yet to be born'            
repo.head.ref.set_tracking_branch(origin.refs.master)
origin.pull()
于 2015-02-02T06:46:23.697 回答
1

我不知道如何正确解决这个问题,但唯一的想法是在 create_head 之后重置硬回购。

import git

repo = git.Repo.init('.')
origin = repo.create_remote('origin', '/home/paweber/git/my-repo.git')
origin.fetch()            
repo.create_head('master', origin.refs.master).set_tracking_branch(origin.refs.master)
origin.pull()
repo.head.reset('--hard')

之后,所有进一步的拉动都应该正常工作。

于 2015-01-30T10:57:20.187 回答