我想从GitHub克隆一个仓库,但问题是我不想要主分支;我想要这个未批准的拉取请求中的版本。
我能否克隆拉取请求版本而不是主仓库?
git fetch origin pull/<pr_number>/head:<local_branch_name>
git switch <local_branch_name>
git config --global alias.pr '!f() { git fetch -fu ${2:-origin} refs/pull/$1/head:pr/$1 && git checkout pr/$1; }; f'
git pr <pr_number>
来检查任何PR,或者如果你的github远程不是命名为origin
,则可以运行git pr <pr_number> <remote>
。git fetch origin pull/<#>/head:<local_branch_name>
(引自:https://coderwall.com/p/z5rkga) - schlamar.gitconfig
文件下的[alias]
里:pr = "!f() { git fetch $1 pull/$2/head:pull_$2; git co pull_$2; }; f"。通过这种方式,我只需要键入
git pr upstream 62,下一刻我就会在来自upstream的第62个PR的新分支上了!如果你总是使用
origin,你可以将其硬编码代替
$1`,但对于我而言这样切换比较麻烦。 - matt---co
的别名用于检出。 - giraffesyo你可以使用-b
选项克隆你想要的分支,对于拉取请求:
git clone https://github.com/user_name/repo_name.git -b feature/pull_request_name dir_name
在您的情况下,您想要克隆的分支是拉取请求的源分支(feature/mongoose-support
):
git clone https://github.com/berstend/frappe.git -b feature/mongoose-support ./mongoose-support
git fetch origin refs/pull/PR_NUMBER/head:NEW_LOCAL_BRANCH
例如:
git fetch origin pull/611/head:pull_611
git checkout pull_611
进行更改,提交它们,PUSH并从您在GitHub上的分支中打开新的PR
git clone git://github.com/dweldon/frappe
cd frappe
git pull origin pull/2/head
git pull
会将其他分支合并到当前分支,通常在进行Pull Request(PR)时,您只需使用git fetch
来获取原作者的代码(它可以作为FETCH_HEAD访问)。如果您确实想要合并,请注意提及pull/2/merge
(而不是pull/2/head
)-这会使GitHub向您提供一个精确的合并提交,就像您现在单击[合并]按钮一样。 - Beni Cherniavsky-Paskingithub3.py/.git/config
文件中有以下内容。[remote "github"]
fetch = +refs/heads/*:refs/remotes/github/*
fetch = +refs/pull/*/head:refs/remotes/github/pr/*
url = git@github.com:sigmavirus24/github3.py
第一行是每个远程都标准的内容,但github
被替换为远程的名称。这意味着远程头(或该服务器上分支的头)被“映射”到以github/
为前缀的本地远程。因此,如果我执行git fetch github
并且GitHub上有一个分支在我的机器上尚未被注意到,它将下载该分支,然后我可以这样切换到它:git checkout -t github/branch_name
。
第二行做的也是同样的事情,但它是针对拉取请求而不是标准的git分支。这就是为什么你看到refs/pull/*/head
。它获取GitHub上每个拉取请求的头,并将其映射到github/pr/#
。因此,如果有人发送了一个拉取请求,编号为62(例如),那么您需要执行:
git fetch github
git checkout -t github/pr/62
假设还未存在名为 pr/62
的本地分支,那么你现在就在这个本地分支上了。这样做很好,因为你不必跟踪其他人的远程仓库或分支。
git clone https://github.com/berstend/frappe.git -b feature/mongoose-support /my_clone
。 - Fresheyeballgit fetch github
命令后,就可以使用 git co -t github/pr/#
命令了。这样做可以避免复制粘贴远程URL、查找分支名称等繁琐步骤。你会获得简洁准确的分支名称,而不必再费力处理这些问题。但我知道这可能会让你感到压力很大。 - Ian Stapleton Cordascogit://github.com/berstend/frappe.git
),然后检出他创建拉取请求的分支(feature/mongoose-support
)。(cd /tmp && git clone --depth 1 https://github.com/tj/git-extras.git && cd git-extras && sudo make install)
git pr
。$ git pr 62 [remote]
clone
而是为了fetch
,请参考:https://dev59.com/Omw15IYBdhLWcg3wO5SX - Ciro Santilli OurBigBook.com