developer tip

내가 소유하지 않은 브랜치에 대한 병합되지 않은 풀 리퀘스트를 어떻게 가져올 수 있습니까?

optionbox 2020. 11. 10. 08:01
반응형

내가 소유하지 않은 브랜치에 대한 병합되지 않은 풀 리퀘스트를 어떻게 가져올 수 있습니까?


NServiceBus 리포지토리에서 특정 풀 요청 (아직 메인 스트림으로 처리되지 않은)을 가져와야합니다.

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

분명히 내 repo는 아니지만 해당 풀 요청에 존재하는 변경 사항이 필요합니다.

이를 수행하는 가장 좋은 방법은 무엇입니까?


저장소로 가져 오기를 가져 오려면 :

git fetch git@github.com:jboss/jboss-common-beans.git refs/pull/4/head

그런 다음 FETCH_HEAD로 원하는 것을 수행하십시오.

git checkout -b new-branch FETCH_HEAD

git pull origin pull/28/head

또는

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

아직 병합되지 않은 pull 요청을 가져올 수 있습니까?


다음과 같이 할 수 있습니다.

1) 업스트림 리모컨 추가 :

git remote add upstream git@github.com:Particular/NServiceBus.git

2) 그 후, ID별로 새 브랜치에 대한 풀 요청을 체크 아웃 할 수 있습니다.

git fetch upstream pull/PULL_REQUEST_ID/head:NEW_BRANCH_NAME

그러면 NEW_BRANCH_NAMEPR 코드가 포함 된 분기 가 생깁니다.

별칭 추가 :

나만큼 자주이 작업을 수행하는 경우 별칭 을 설정 하는 것이 좋습니다. 내 .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

어려운 상황의 경우 (특히 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

GitHub에서이 도움말 문서를 참조하십시오. https://help.github.com/articles/checking-out-pull-requests-locally


github / hub

https://github.com/github/hub 는 GitHub API의 추가 정보를 사용하여이 사용 사례와 기타 사용 사례를 아름답게 처리하는 GitHub CLI 도우미입니다. 예 :

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

결과:

  • 우리는 이제 <USERID>-<BRANCH_NAME>PR을 포함하는 라는 지점 에 있습니다.

    자동으로 설정된 좋은 브랜치 이름에 유의하십시오.

  • 해당 분기는 포크의 원래 분기를 추적하도록 설정됩니다. 즉, 다음을 .git/config포함합니다.

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

    따라서 추가 커밋이 푸시되면 git fetch직접 수행 수 있습니다.

hubGo에 익숙하지 않은 경우 Linux에 설치 하는 것은 현재 고통 스럽지만 그만한 가치가 있습니다. 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에 웹 UI에 복사 붙여 넣기 치트 시트를 요청했습니다. https://github.com/isaacs/github/issues/449


업스트림 리포지토리를 업스트림 원격으로 추가하면 (@elias가 지적한대로) :

$ git remote add upstream git@github.com:Particular/NServiceBus

기본적으로 pull 요청을 가져 오도록 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'

나를 위해 일한 명령은 다음과 같습니다.

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.


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


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

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.


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!!!!!!!!!!!!!!

참고URL : https://stackoverflow.com/questions/6743514/how-can-i-fetch-an-unmerged-pull-request-for-a-branch-i-dont-own

반응형