如何在GitHub PR合并之前进行更多的工作?

huangapple go评论69阅读模式
英文:

How to do further work on github PR before merge?

问题

有人从分叉存储库向我的GitHub存储库提交了一个PR。它的99%正常,但剩下的1%我不想在PR审查、他修复、我再次审查的循环中来回反复,我想直接解决它们。

在GitHub上有没有办法自己进一步处理PR,即在合并之前我的更改会显示在他的PR中?

$ git fetch origin pull/11
fatal: 未找到远程引用 pull/11

而且通常的 git pull 命令手动拉取PR的更改到我的本地存储库对我也不起作用:

$ git pull
当前分支 master 已经是最新的。

$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

因为当我检查GitHub上的分支时,没有与该PR相关的分支:

如何在GitHub PR合并之前进行更多的工作?

英文:

Say someone submits a PR from a forked repository to my repo on Github. It's 99% OK but for the remaining 1%, I don't want to go back and forth with the PR-review and he-fix and I-review-again cycles, and want to go straightforward and fix them myself.

Is there a way to do further work on github PR myself, i.e., my changes show up in his PR before merging it?

$ git fetch origin pull/11
fatal: couldn't find remote ref pull/11

And the normal git pull command to manually pull the changes of the PR into my local repo doesn't work for me either:

$ git pull
Current branch master is up to date.

$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

As when I check the branches in github, there is no branch for that PR:

如何在GitHub PR合并之前进行更多的工作?

答案1

得分: 1

你可以使用 git pull 命令手动将PR中的更改拉取到当前分支,无论是主分支还是开发分支。只需在GitHub上的拉取请求下方查找并点击那个小链接,上面写着“命令行指令”。您可以忽略大部分指令,只需查找以 git pull 开头的一行指令。

然后,您可以进行任何您想要的提交(在拉取请求的基础上,无需合并或修改提交),并将更改推送到适当的位置(例如GitHub上您存储库的主分支)。

英文:

You can do a git pull command to manually pull the changes contributed in the PR into your current branch, whether it is the main branch or a development branch. Just look below the pull request on GitHub and click the little link that says "command line instructions". You can ignore most of the instructions and just look for the one line that starts with git pull.

Then make whatever commits you want to (on top of the pull request, without squashing or amending the commits) and push your changes to wherever is appropriate (e.g. the master branch of your repository on GitHub).

答案2

得分: 0

你可以简单地添加更多的提交到同一个分支并推送它们。GitHub Pull Request 将自动更新这些更改。

Pull Request 是GitHub独有的概念。如果你在使用git,你应该切换到相应的分支。如果你想检出一个Pull Request,你应该使用GitHub CLI而不是直接使用git(在你的问题链接的文档中,请注意命令是gh而不是git)。

如果在你的仓库中看不到其他分支(根据更新后的问题截图),有可能PR是由其他人从一个派生的仓库中打开的。在这种情况下,你不能直接编辑要合并的代码。你的选择是:

  • 请求PR所有者按照你的要求编辑代码。
  • 合并PR,然后随后按照你的需求编辑代码。
  • 关闭PR,然后手动合并你想要的代码。不建议这样做,因为这可能被认为是对PR所有者的不礼貌,将他们的工作归功于自己。但如果你仍然想这样做,可以将他们的仓库克隆到你的电脑上,检出正确的分支,将其合并到你的仓库中,然后推送代码。查看此答案,了解如何在不同仓库之间合并代码的方法
英文:

You can simply add more commits to the same branch and push them. GitHub Pull Request will be automatically updated with those changes.

Pull Request is a GitHub-only concept. If you're using git, you should checkout the corresponding branch. If you want to checkout a pull request, you should use GitHub CLI instead of git directly (in the documentation linked in your question, notice that command is gh, not git).

If you don't see any other branches in your repository (as per screenshot in the updated question), it's possible that PR was opened from a forked repository by someone else. In that case you can't edit code to be merged directly. Your options:

  • Ask the PR owner to edit the code as you'd like.

  • Merge the PR and edit the code as you wish afterwards.

  • Close the PR and manually merge the code you want. Wouldn't recommend this, since it may be considered rude to the PR owner, taking credit for their work. But if you still want to do it, clone their repository to your computer, checkout the correct branch, merge it into your repository, and push code. See this answer on how to merge code between different repositories.

答案3

得分: 0

安装 gh,使用命令 brew install gh。然后输入以下命令:

gh pr checkout 11

(假设这是正确的PR编号)。现在,您可以进行编辑、添加、提交和推送操作。您的提交将附加到GitHub上的PR中。

英文:

Install gh by saying brew install gh. Then say

gh pr checkout 11

(assuming that that is the correct number of the PR). You can now edit, add, commit, and push. Your commit(s) will be appended to the PR at GitHub.

huangapple
  • 本文由 发表于 2023年1月9日 03:33:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75050701.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定