如何在 SourceTree 本地签出分叉的拉取请求?

How to checkout a forked pull request locally in SourceTree?

有时 pull requests are quite complex and/or potentially bug-ridden. In that case it can be a little unreasonable to spot check a pull request solely by reading the code. It makes more sense to checkout, pull, and build that pull request locally first before merging it. In this manner a repo 维护者可以更加确信拉取请求没有引入任何回归问题。

我可以从 command-line fairly easily, but I would prefer to use SourceTree. I know using the command-line is simple and straightforward, but I believe in using GUI tools whenever possible over command-line tools. SourceTree has become the de facto standard gui git client for windows 签出拉取请求,所以 SourceTree 似乎具有此基本功能。但是,我尝试了许多不同的命令和对话框,但我似乎无法访问 SourceTree 中的拉取请求。

是否可以仅使用 SourceTree 将拉取请求拉取到本地?怎么样?

无法直接在 SourceTree 中从分叉的仓库签出拉取请求。

我也把这个问题转发给了 atlassian 问答板,the question was answered in a comment

From what I know there is not a way to do this action within sourcetree directly, as sourcetree is used to work with the git repos that you have locally and not to work with PRs or remote repos that you may have access to in Bitbucket or Github.

本质上,您必须单独克隆另一个存储库,然后切换到用于拉取请求的任何分支。

遗憾的是,这个功能在命令行中非常简单,但在 SourceTree 的 Gui 中却比较麻烦。

您可以获取 pr 分支,然后像对待任何其他分支一样对待 PR。参见 https://gist.github.com/piscisaureus/3342247

基本上,所有 PR 都在 refs/pull/*/head 下,您经常使用的所有分支都在 refs/heads

我在寻找不使用命令 window 的更好方法时遇到了你的问题。

我目前的做法是:

  1. 将发起 PR(拉取请求)的分支添加为远程。这可以通过 Repository -> Repository Settings -> Remote 中的设置完成,然后单击 'Add'.
  2. 获取分支列表并
  3. 查看 PR 的分支。

它不提供对 PR 的直接访问权限,但它确实为我提供了更改的本地副本。我仍然接受并合并或通过 github 要求修改。如果 PR 发生变化,我只是将更新拉入分支。

Sourcetree 似乎将 PR 视为管理 return 对原始存储库的本地更改的一种方式。

根本不可能在 Bitbucket 上检出分叉的回购协议。

您必须下载补丁并申请测试

# Download the patch file.
curl -u user:password https://bitbucket.org/api/2.0/repositories/{user}/{repo}/pullrequests/{pull_no}/patch -L -o name.patch

# Apply the patch file to your local Git checkout.
git apply name.patch

将您的 .git/config 更改为以下内容并进行抓取:

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git@github.com:{user}/{repo}.git
+   fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

我发现 Abhishek 的回答很好用!

这是我的做法:

  • 转到存储库“.git”文件夹并打开 config-file
  • "[remote "origin"] 条目上,将提取更改为:fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
  • 关闭 SourceTree 中的 repo-tab 并重新打开它。
  • 单击工具栏中的“获取”以获取所有 PR-branches。

没有 PR 显示为分支:

对于 Bitbucket,我使用了 Abhishek 的答案,但添加了 fetch = +refs/pull-requests/*:refs/remotes/origin/pull-requests/* 而不是 fetch = +refs/pull/*/head:refs/remotes/origin/pr/*