dsuikgi9199 2015-07-07 18:39
浏览 55
已采纳

将当前分支与git2go中的上游(或任何其他参考)合并

I'm trying to replicate the outcome of the following command in git2go:

git merge -X theirs --no-ff -m "Commit msg" <commit>

I'm able to successfully fetch the upstream remote using remote.Fetch(nil, nil, ""), but I cannot do the actual merge. This is the code I'm using for merging:

// get the upstream ref's annotated commit to merge in
head, _ := repo.Head()
upstream, _ := head.Branch().Upstream()
annotatedCommit, _ := repo.AnnotatedCommitFromRef(upstream)

// prepare merge and checkout options
mergeOpts, _ := git.DefaultMergeOptions()
mergeOpts.FileFavor = git.MergeFileFavorTheirs
checkoutOpts := git.CheckoutOpts{
    Strategy: git.CheckoutUseTheirs,
}

// do the merge
err := repo.Merge([]*git.AnnotatedCommit{annotatedCommit}, &mergeOpts, &checkoutOpts)
// no error here

I understand that after this I need to check the index for any conflicts, and actually do the commit with the two parents, however I'm stuck here at the moment because the Merge() doesn't appear to be doing anything (no merge, no checkout).

  • 写回答

1条回答 默认 最新

  • dou91855 2015-07-08 10:31
    关注

    Checkout is performing a dry run by default, so to be able to successfully merge I had to use something like this:

    checkoutOpts := git.CheckoutOpts{
        Strategy: git.CheckoutSafe | git.CheckoutRecreateMissing | git.CheckoutAllowConflicts | git.CheckoutUseTheirs,
    }
    

    The only documentation available is in the checkout.go source.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置