用于处理GitHub拉取请求的正确git配置是什么? [英] What is the correct git config for working with GitHub pull requests?

查看:106
本文介绍了用于处理GitHub拉取请求的正确git配置是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何查看GitHub拉请求吗?

虽然将fetch = +refs/pull/*/head:refs/remotes/origin/pr/*添加到.git/config确实允许获取和签出,但拉动作失败:

While adding fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to .git/config does allow fetch and checkout, pull actions fail:

[remote "origin"]
    url = https://github.com/the/repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*
    fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

获取和结帐工作正常:

$ git fetch origin

...一切都很好

$ git checkout -b "pr-123" origin/pr/123
Branch pr-123 set up to track remote branch pr/123 from origin.
Switched to a new branch 'pr-123'

...成功,得到了代码!

... success, got the code!

但是拉失败:

$ git pull
Your configuration specifies to merge with the ref 'refs/heads/pr/123' 
from the remote, but no such ref was fetched.

...失败.

我可以手动指定参考:

$ git pull origin refs/pull/123/head

,这有效.但是我该如何配置配置文件,以便:

and this works. But how can I configure the config file so that:

  1. 获取并添加结帐仍然有效,并且
  2. 后续的拉动操作无需手动指定远程引用即可?


我发现如果我编辑配置文件并更改:


I have found that if I edit the config file and change:

[branch "pr-123"]
    remote = origin
    merge = refs/heads/pr/123

收件人:

[branch "pr-123"]
    remote = origin
    merge = refs/pull/123/head  # <-- here is the change

...然后git pull正常工作.无需为每个拉取请求手动编辑配置文件,如何实现?

... then git pull works fine. How can this be achieved without manually editing the config file for every pull request?

推荐答案

我想我找到了一个解决方案,而且非常简单:fetch = +refs...的行顺序很重要!

I think I found a solution, and it's unbelievably simple: Order of the lines with fetch = +refs... matters!

我更改了:

[remote "origin"]
    url = https://github.com/the/repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*
    fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

收件人:

[remote "origin"]
    url = https://github.com/the/repo.git
    fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
    fetch = +refs/heads/*:refs/remotes/origin/*

(交换了最后两行)

现在一切正常(fetchcheckoutpull).

Now everything works (fetch, checkout, pull).

我仍在等待看到此配置的一些(意外)问题,但到目前为止效果很好...

I'm still waiting to see some (un)expected problems with this configuration, but so far so good...

这篇关于用于处理GitHub拉取请求的正确git配置是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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