如何在GitHub上更改PR的所有者/如何命令开放的GitHub PR [英] How to change the owner of a PR on GitHub / How to commandeer an open GitHub PR

查看:372
本文介绍了如何在GitHub上更改PR的所有者/如何命令开放的GitHub PR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现GitHub中缺少的此功能令人沮丧,因此我在此处记录了解决方法,以帮助下一个人.欢迎使用其他更好的解决方法.

此问题与

那个 username :我们该如何更改呢?用例示例:

  1. 打开此PR的队友刚刚离开公司,我们想指挥(接任)并完成他们的PR.
  2. 工作量的变化需要您从另一位队友那里接手部分完成的PR.您如何才能将PR更改为您的名字?

假定每个人都具有对整个仓库的完全推入访问权限,这意味着您可以始终向/从彼此的分支推入/拉出.

解决方案

有时,一项任务会从一个团队成员转移到另一个团队成员,或者一个团队成员离开团队.当发生这种情况时,最好指挥官"或接管他们的PR,以使其成为您的PR.据我所知,这在GitHub上尚不可能.

在.

  • 在本地签出他们的分支机构

      git提取源的them_branch_namegit checkout them_branch_name 

  • (可选),但但建议,将其分支的本地副本重命名为您喜欢的名称.

      git branch -m new_branch_name 

  • 将此作为新分支推送到GitHub上的远程 origin .这会推送到您的远程分支,并允许您在GitHub上以您的名字打开一个新PR:

      git push --set-upstream来源new_branch_name#注意:如果您没有将分支重命名为上述的"new_branch_name",则只需#在这里改用`their_branch_name`. 

  • 首次推送后,GitHub将在您推送的终端中输出一个URL,您可以单击该URL以您的名字打开一个新的PR .打开公关,瞧瞧!现在是您的PR,您只是被征服"了他们的公关!
  • 现在,要推送,您可以致电:

      git push 

  • 要从该分支中​​提取信息,以防万一另一个队友也将更改推送到该分支,您可以指定:

      git pull origin new_branch_name 

  • 现在,当PR完成并审核后,您可以在GitHub上合并它.如果您选择压缩并合并",选项,您的名称将用于最终的单次提交,该提交将合并到 base_branch .

    另请参见:

    1. How to change the author of a PR in GitHub? ...because that question isn't clear if it is asking about how to rewrite the author of a few commits and the push those to github, or actually change the name under which the entire PR was created in the first place. And, the accepted answer to that question was a simple fix to the local .git/config file, which clearly will not solve the GitHub problem I'm talking about here.


      At the top of a GitHub PR you'll see something like this:

      username wants to merge 1 commit into base_branch from their_feature_branch

      Example PR (chosen "at random" from GitHub, just to show the PR author line in the image below). Image:

      That username: how can we change that? Example use-cases:

      1. The team-mate who opened this PR just left the company, and we'd like to commandeer (take over) and finish the PR for them.
      2. Change of work-loads have necessitated you take over a partially-complete PR from another team-mate. How can you switch that PR to be in your name?

      Assume that everyone has full push access to the whole repo, meaning that you can push/pull to/from each other's branches anyway.

      解决方案

      Sometimes, an assignment gets passed off from one team member to another, or, a team member leaves a team. When this happens, it would be nice to "commandeer", or take over, their PR so that it becomes your PR. As far as I can tell, however, this isn't possible on GitHub yet.

      On Phabricator (a paid alternative to GitHub, and originally an internal tool used at Facebook), this is as simple as clicking a button to "Commandeer Revision" (see old documentation here under "Take over another author's change"). This is known as "commandeering someone's diff", where "diff" here is the Phabricator-equivalent to a GitHub PR, or "Pull Request".

      How to commandeer someone else's PR in GitHub; ie: how to change the owner of the open PR so it looks like you opened the PR, not them.

      So, since GitHub doesn't allow commandeering a PR, here are some options:

      1. Continue using their open PR, in which case their name, not yours, gets attached to the final, squashed-and-merged commit in the event you use the "Squash and merge" option to finish the PR. If they did the bulk of the work, that's fine. But, if you are taking over a PR and you are doing the bulk of the work, you'd probably like your name to be attached to the work. So, instead:
      2. Just close their open PR and open your own.

      To do option 1 above: just keep using their open PR, in which their name gets attached to final, squashed merge commit:

      1. Check out their branch locally

        git fetch origin their_branch_name
        git checkout their_branch_name
        

      2. Optionally, rename your local copy of their branch to something you like

        git branch -m new_branch_name
        

      3. Set the upstream for this branch so that when you git push it will push to their remote branch name which is attached to their open PR:

        git push --set-upstream origin their_branch_name
        

      4. Now, to push you can just call:

        git push
        

      5. And to pull from that branch, in case another team-mate pushes changes to it too, you can specify:

        git pull origin their_branch_name
        

      Now, whenever the PR is complete and reviewed, you can merge it via GitHub. If you choose the regular merge option you'll get credit for your commits. If you choose the "squash and merge" option, the original author, NOT you gets full credit for the entire merge. This is dumb and should be fixed by GitHub, but, that's how it is.

      Here's how to do option 2 above: just close their PR and open your own:

      1. Go to the bottom of their PR and click "Close pull request": .
      2. Check out their branch locally

        git fetch origin their_branch_name
        git checkout their_branch_name
        

      3. Optionally, but recommended, rename your local copy of their branch to something you like.

        git branch -m new_branch_name
        

      4. Push this as a new branch to the remote origin on GitHub. This pushes to your remote branch and allows you to open a NEW PR under YOUR name on GitHub:

        git push --set-upstream origin new_branch_name
        # Note: if you didn't rename the branch to `new_branch_name` above, just
        # use `their_branch_name` here instead.
        

      5. After pushing like that for the first time, GitHub will output a URL in the terminal where you pushed, which you can click on to open a new PR under your name. Open a PR and voilá! It's now YOUR PR and you've just "commandeered" their PR!
      6. Now, to push you can just call:

        git push
        

      7. And to pull from that branch, in case another team-mate pushes changes to it too, you can specify:

        git pull origin new_branch_name
        

      Now, when the PR is complete and reviewed, you can merge it on GitHub. If you choose the "squash and merge" option your name will be used for the final, single commit which gets merged to the base_branch.

      See also:

      1. How can I push a local Git branch to a remote with a different name easily?

      这篇关于如何在GitHub上更改PR的所有者/如何命令开放的GitHub PR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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