如何获取我不拥有的分支的未合并拉取请求?

发布于 2024-11-25 03:09:35 字数 322 浏览 8 评论 0原文

我需要在 NServiceBus 存储库中拉入特定的拉取请求(尚未处理到主流中):

https://github.com/johnsimons/NServiceBus/commit/d8524d53094e8181716e771c1023e968132abc15

这显然不是我的存储库,但我需要该拉取请求中存在的更改。

最好的方法是什么?

I need to pull in a specific pull request (that hasn't been processed into the main stream yet) in the NServiceBus repo:

https://github.com/johnsimons/NServiceBus/commit/d8524d53094e8181716e771c1023e968132abc15

It's obviously not my repo, but I need the changes that exist in that pull request.

What is the best way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

-小熊_ 2024-12-02 03:09:35
git pull origin pull/28/head

或者

git fetch origin pull/28/head:28
git checkout 28

我可以拉取尚未合并的拉取请求吗?

git pull origin pull/28/head

Or

git fetch origin pull/28/head:28
git checkout 28

Can I pull a not-yet-merged pull request?

绻影浮沉 2024-12-02 03:09:35

要将拉取到您的存储库中:

git fetch [email protected]:jboss/jboss-common-beans.git refs/pull/4/head

然后使用 FETCH_HEAD 执行您想要的操作:

git checkout -b new-branch FETCH_HEAD

To fetch a pull into your repository:

git fetch [email protected]:jboss/jboss-common-beans.git refs/pull/4/head

Then do whatever you want with FETCH_HEAD:

git checkout -b new-branch FETCH_HEAD
旧时浪漫 2024-12-02 03:09:35

您可以执行以下操作:

1) 添加上游远程:

git remote add upstream [email protected]:Particular/NServiceBus.git

2) 之后,您可以根据其 ID 将任何拉取请求检出到新分支:

git fetch upstream pull/PULL_REQUEST_ID/head:NEW_BRANCH_NAME

然后您将拥有一个名为 NEW_BRANCH_NAME 的分支,其中包含 PR代码。

添加别名:

如果您像我一样经常这样做,您可能需要设置 它的一些别名
我的 .gitconfig 中有这个:

[alias]
    fetch-pr = "!f(){\
        [ -z \"$1\" ] && { echo Usage: git fetch-pr PULL_REQUEST_ID [REMOTE_NAME] [NEW_BRANCH_NAME]; exit 1; }; \
        remote=${2:-origin}; \
        branch=${3:-pr-$1}; \
        git fetch $remote \"pull/$1/head:$branch\"; \
        }; f "
    pr = "!f(){\
        branch=${3:-pr-$1}; \
        git fetch-pr \"$@\"; \
        git switch $branch; \
        }; f "

有了上面的内容,我可以这样做:

git fetch-pr 123              # fetch PR #123 into branch pr-123
git fetch-pr 123 some-branch  # fetch PR #123 into some-branch
git pr 123                    # fetch and switch to the branch

You can do this:

1) Add the upstream remote:

git remote add upstream [email protected]:Particular/NServiceBus.git

2) After that, you can checkout any pull request to a new branch per its ID:

git fetch upstream pull/PULL_REQUEST_ID/head:NEW_BRANCH_NAME

Then you'll have a branch named NEW_BRANCH_NAME containing the PR code.

Adding an alias:

If you do this as often as me, you may want to setup some aliases for it.
I have this in my .gitconfig:

[alias]
    fetch-pr = "!f(){\
        [ -z \"$1\" ] && { echo Usage: git fetch-pr PULL_REQUEST_ID [REMOTE_NAME] [NEW_BRANCH_NAME]; exit 1; }; \
        remote=${2:-origin}; \
        branch=${3:-pr-$1}; \
        git fetch $remote \"pull/$1/head:$branch\"; \
        }; f "
    pr = "!f(){\
        branch=${3:-pr-$1}; \
        git fetch-pr \"$@\"; \
        git switch $branch; \
        }; f "

With the above, I can do:

git fetch-pr 123              # fetch PR #123 into branch pr-123
git fetch-pr 123 some-branch  # fetch PR #123 into some-branch
git pr 123                    # fetch and switch to the branch
满身野味 2024-12-02 03:09:35

对于困难的情况(特别是如果您没有签出 git-repo),我认为最简单的方法是应用补丁。为此,只需在 github 上打开 pull-request 并向 URL 添加“.patch”,下载并应用补丁即可。

例子:

cd cordova-plugin-media
wget https://github.com/apache/cordova-plugin-media/pull/120.patch
patch -p1 < 120.patch

For difficult situations (especially if you have not a checked out git-repo), I think the simplest way is to apply a patch. For this just open the pull-request on github and add a ".patch" to the URL, download it and apply the patch.

Example:

cd cordova-plugin-media
wget https://github.com/apache/cordova-plugin-media/pull/120.patch
patch -p1 < 120.patch
浅黛梨妆こ 2024-12-02 03:09:35

github/hub

https://github.com/github/hub 是一个 GitHub CLI 帮助程序,可以使用 GitHub API 中的额外信息完美地处理此用例和其他用例。例如:

git clone https://github.com/github/hub
# Just copy paste the URL.
hub checkout https://github.com/github/hub/pull/970

结果:

  • 我们现在位于包含 PR 的名为 - 的分支上。

    请注意自动为我们设置的良好分支名称。

  • 该分支设置为跟踪分叉上的原始分支,即 .git/config 包含:

    [分支“-”]
        远程=反义词
        合并=参考/头/票/969
        变基=真
    

    因此,如果进一步提交被推送,我们可以直接git fetch它们。

如果您不熟悉 Go,目前在 Linux 上安装 hub 会很痛苦,但这是值得的。在 Ubuntu 14.04 上,存储库上的 Go 太旧了,因此 GVM 是最好的选择:

bash < <(curl -LSs 'https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer')
. "$HOME/.gvm/scripts/gvm"
gvm install 'go1.4'
gvm use 'go1.4' --default
go get github.com/github/hub

我有还要求 GitHub 在 Web UI 上为我们提供一份复制粘贴备忘单:https://github.com/isaacs/github/issues/449

github/hub

https://github.com/github/hub is a GitHub CLI helper that deals with this and other use cases beautifully using extra information from the GitHub API. E.g.:

git clone https://github.com/github/hub
# Just copy paste the URL.
hub checkout https://github.com/github/hub/pull/970

Result:

  • we are now on a branch called <USERID>-<BRANCH_NAME> that contains the PR.

    Note the good branch name which was automatically set for us.

  • that branch is set to track the original branch on the fork, i.e. .git/config contains:

    [branch "<USERID>-<BRANCH_NAME>"]
        remote = retronym
        merge = refs/heads/ticket/969
        rebase = true
    

    So if further commits get pushed, we can git fetch them directly.

Installing hub on Linux is currently a pain if you're not familiar with Go, but worth it. On Ubuntu 14.04, the Go on the repositories is too old, so GVM is the best option:

bash < <(curl -LSs 'https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer')
. "$HOME/.gvm/scripts/gvm"
gvm install 'go1.4'
gvm use 'go1.4' --default
go get github.com/github/hub

I have also asked GitHub to give us a copy paste cheatsheet on the web UI at: https://github.com/isaacs/github/issues/449

岁月染过的梦 2024-12-02 03:09:35

一旦你将上游存储库添加为上游远程(正如 @elias 指出的那样):

$ git remote add upstream [email protected]:Particular/NServiceBus

你可以配置 git 默认情况下获取拉取请求:

$ git config --local --add remote.upstream.fetch '+refs/pull/*/head:refs/remotes/upstream/pr/*'

所以,让我们获取它:

$ git fetch upstream
Fetching upstream
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 4 (delta 2), reused 4 (delta 2), pack-reused 0
Unpacking objects: 100% (4/4), done.
From https://github.com/Particular/NServiceBus
 * [new ref]         refs/pull/1/head -> upstream/pr/1
 * [new ref]         refs/pull/2/head -> upstream/pr/2

并检查一下:

$ git checkout pr/2
Branch pr/2 set up to track remote branch pr/2 from upstream.
Switched to a new branch 'pr/2'

Once you added the upstream repo as an upstream remote (as @elias pointed out):

$ git remote add upstream [email protected]:Particular/NServiceBus

You can configure git to fetch pull requests by default:

$ git config --local --add remote.upstream.fetch '+refs/pull/*/head:refs/remotes/upstream/pr/*'

So, let's fetch it:

$ git fetch upstream
Fetching upstream
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 4 (delta 2), reused 4 (delta 2), pack-reused 0
Unpacking objects: 100% (4/4), done.
From https://github.com/Particular/NServiceBus
 * [new ref]         refs/pull/1/head -> upstream/pr/1
 * [new ref]         refs/pull/2/head -> upstream/pr/2

And check it out:

$ git checkout pr/2
Branch pr/2 set up to track remote branch pr/2 from upstream.
Switched to a new branch 'pr/2'
_蜘蛛 2024-12-02 03:09:35

这是对我有用的命令。

我假设一个人已经在本地将一个存储库(例如 pytorch )克隆到他/她的系统。之后,一些志愿者/爱好者贡献了一些代码并向远程存储库发布了 PR,但它尚未合并到主分支或任何其他分支中。因此,

首先我们必须对 github 远程存储库执行 git Remote add 操作:

# I've given the name `original`; you can give some other name as per your liking
$ git remote add original https://github.com/pytorch/pytorch

然后 cd 进入存储库 pytorch 然后只需执行以下操作:

# after this, the unmerged PR should be pulled to your local repo
$ git fetch original pull/<pull_number>/head    # 23, 123 etc.,

现在,待处理的 PR 已提取到您的本地存储库中,并且提取的提示将位于 FETCH_HEAD 中。如果您想在本地合并此待处理的 PR,则只需执行以下操作:

$ git merge FETCH_HEAD

在此之后,如果您这样做:

$ git status

您应该能够看到本地存储库位于 n 次提交是待处理 PR 的一部分(即可以在单个 PR 中发出超过 1 次提交)。因此,提交的数量取决于待处理 PR 中包含的提交。

Here're the commands that worked for me.

I'll assume that one has already cloned a repo (for e.g. pytorch ) to his/her system locally. After that some volunteer/enthusiast has contributed some code and issued a PR to the remote repository but it has not been merged into the master or any other branch yet. So,

First we'll have to do git remote add to the github remote repository:

# I've given the name `original`; you can give some other name as per your liking
$ git remote add original https://github.com/pytorch/pytorch

Then cd into the repository pytorch and then simply do:

# after this, the unmerged PR should be pulled to your local repo
$ git fetch original pull/<pull_number>/head    # 23, 123 etc.,

Now, the pending PR has been fetched into your local repo and the tip of your fetch would be in FETCH_HEAD. If you want to merge this pending PR locally, then simply do:

$ git merge FETCH_HEAD

After this, if you do:

$ git status

You should be able to see that the local repo is ahead of n commits that were part of the pending PR (i.e. it's possible to issue more than 1 commit in a single PR). So, the number of commits depend on the commits contained in the pending PR.

爱要勇敢去追 2024-12-02 03:09:35

这是 GitHub 文档中的解决方案:

从项目存储库中,签出新分支并测试更改。

git checkout -b GithubUserID-branchName branchName
git pull https://github.com/GithubUserID/reponame.git branchName

其中:

  1. GithubUserID 是打开拉取请求的人的用户名。
  2. branchName 是分支的名称,例如 master
  3. reponame 存储库名称,如 demo-todo

示例:

git checkout -b felix123-master master
git pull https://github.com/felix123/demo-todo.git master

This is the solution from GitHub docs:

From your project repository, check out a new branch and test the changes.

git checkout -b GithubUserID-branchName branchName
git pull https://github.com/GithubUserID/reponame.git branchName

Where:

  1. GithubUserID is the username of the person who opened the pull request.
  2. branchName is the name of the branch for example master
  3. reponame the repository name like demo-todo

Example :

git checkout -b felix123-master master
git pull https://github.com/felix123/demo-todo.git master
完美的未来在梦里 2024-12-02 03:09:35

如果您只想将其他存储库中未合并的拉取请求添加到您自己的存储库中,
不需要所有的并发症(如其他答案中大部分所示)。

相反,只需进入您自己的存储库并使用其提交哈希提取提交(从 PR 源)。

git pull https://bitbucket.org/SomeUser/SomeProjectRepo/commits/c15...db2

通过这种方式,您将获得一堆新编辑的文件,就好像您自己编辑了它们一样。如果您想使用一些标签/标签来​​提交这些,则由您决定。

如果您想将所有新闻推送到您自己的 GitHub 存储库,只需照常执行:

git commit -m "Added something by Anonymous"
git push -u origin master

If you just want to add one unmerged Pull Request from some other repo, to your own,
there is no need for all complications (as mostly shown in other answers).

Instead just go into your own repo and pull in the commit (from PR source), using its commit hash.

git pull https://bitbucket.org/SomeUser/SomeProjectRepo/commits/c15...db2

Doing it this way, you will just have a bunch of new edited files, as if you had edited them yourself. It's then up to you if you want to commit these with some tag/label.

If you then want to push all news up to your own GitHub repo, just do as always:

git commit -m "Added something by Anonymous"
git push -u origin master
云胡 2024-12-02 03:09:35

下面是让你的“git fetch”命令在运行“git fetch”时获取所有拉取请求,

将下面的内容添加到~/.gitconfig中,

[remote "origin"]
fetch = +refs/pull-requests/*/from:refs/remotes/origin/pr/*

注意参考“refs/pull-requests/”具有存储命名约定,对于git hub,你可能需要不同的格式

below is to make your 'git fetch' command to fetch all pull requests when run "git fetch"

add below into ~/.gitconfig

[remote "origin"]
fetch = +refs/pull-requests/*/from:refs/remotes/origin/pr/*

note the reference "refs/pull-requests/" has the stash naming convention, for git hub, you may need different format

氛圍 2024-12-02 03:09:35

Github 有明确的文档,用于将拉取请求合并到本地存储库中:

https://help.github.com/en/articles/checking-out-pull-requests-locally

归根结底,GitHub 中的拉取请求只是基础存储库,其中分支名称是序列号。上面的文章向您展示了如何找到这个数字以及 git 命令行魔法,以使用您想要的任何分支名称将其拉入本地存储库。

我找不到类似简单的方法将拉取请求合并到我在 GitHub 上创建的分叉中。

Github has clear doc for merging the pull request into a local repo:

https://help.github.com/en/articles/checking-out-pull-requests-locally

It boils down to knowing that a pull request in GitHub is just a branch in the base repo where the branch name is a sequence number. The above article shows you how to find this number and the git command line magic to pull it into your local repo with whatever branch name you'd like.

I could not find a similarly simple way to merge the pull request into a fork I created on GitHub.

凉宸 2024-12-02 03:09:35

我找到了这个问题的解决方案 - 从不同机器上未合并的 PR 中提取更改,我在 git bash 上做了以下事情
1. 您必须在机器 2 上克隆远程存储库
2. 执行 git checkout (生成 PR 的分支)
3. 进行git拉取
并完成!!!!!!!!!!!!!!!

I found this solution to this problem - pulling changes from unmerged PR on different Machine , I did following things on git bash
1. You must have taken clone of remote repository on machine 2
2. do git checkout (branch on which PR was generated)
3. do git pull
and done!!!!!!!!!!!!!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文