做git fetch&& git从远程与git2go合并 [英] Doing git fetch && git merge from remote with git2go

查看:189
本文介绍了做git fetch&& git从远程与git2go合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用libgit2 / git2go v0.22并试图从远程存储库实施类似于git pull的操作。在这种情况下,工作目录不会写入任何内容:不更改,不提交,不推送。它只会从远程获取数据。

I'm using libgit2/git2go v0.22 and trying to implement something similar to a "git pull" from a remote repository. In this case The working directory doesn't write anything: no changes, no commits, no push. It will only pull data from the remote.

使用git2go我可以克隆远程存储库,加载/查找远程原点,获取远程数据库,列出远程标题等。似乎只有一步不工作是合并。
我的代码看起来像这样(我忽略了错误处理):

Using git2go I can clone the remote repository, load/lookup a remote origin, fetch the remote, list remote headers, etc. It seems that the only step not working is the merge. My code looks like this (i'm ommiting the error handling):

repo, err:= git.OpenRepository(sitesConfig.Sites[SiteName].Path)
remote, err:= repo.LookupRemote("origin")
err = remote.SetCallbacks(&rcbs)
err = remote.Connect(git.ConnectDirectionFetch)
err = remote.ConnectFetch()

remote_master, err := repo.LookupReference("refs/remotes/origin/master")
mergeRemoteHead, err := repo.AnnotatedCommitFromRef(remote_master)
mergeHeads := make([]*git.AnnotatedCommit, 1)
mergeHeads[0] = mergeRemoteHead
err = repo.Merge(mergeHeads, nil, nil)
repo.StateCleanup()

运行此代码时不会显示任何错误,但工作目录没有更新。在同一个目录中使用git pull和git fetch& git marge origin / master可以正常工作。

No errors appear when running this code, but the working directory is not updated. Using "git pull" and "git fetch && git marge origin/master" on the same directory worked fine.

缺少一些东西吗?最终提交?

Is something missing? A final commit?

推荐答案

您要求连接远程两次( err = remote.Connect(git.ConnectDirectionFetch ) err = remote.ConnectFetch()),但是你不要求任何东西。

You are asking to connect to the remote twice (err = remote.Connect(git.ConnectDirectionFetch) and err = remote.ConnectFetch()), but you're not asking it for anything. Instead of trying to connect twice, use the all-in-one fetch method

remote.Fetch(nil, nil, nil)

来连接,下载和更新远程追踪分支。然后你可以检查是否有更新和合并或做任何你需要的。

to connect, download and update the remote-tracking branches. Then you can check whether there was an update and merge or do whatever you need.

这篇关于做git fetch&& git从远程与git2go合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆