我正在使用github主持一些项目,有人分叉我的回购,并提交了一个公关,我从来没有在叉子中测试公关。我怎样才能检查这个分支并测试它?我能不能把它拉进我的回购箱?还是我检查分叉,然后用这种方式测试分支?
发布于 2020-06-17 07:30:33
有几种不同的方法,但我会仔细研究一下在这种情况下我会做些什么
git remote add <whatever you want the remote to be called> <link to the fork>
这是文件。这将允许您添加和签出分叉中的远程分支。在您描述的工作流中查看PRs时,我通常会执行一个git clean -dfx
(警告:这是一个非常密集的清理,可以消除您所做的未分阶段的工作)、git remote add <whatever you want the remote to be called> <link to the fork>
和git checkout <branch name>
。
如果它已经在您的回购中,您可以通过git branch -a
看到这一点,只需检查它,否则就可以了。
发布于 2020-06-17 07:42:03
基本上,“上游”GitHub存储库提供对叉的PR分支的直接访问(在只读中),这样您就可以获取给定的PR并测试相应的代码pull/ID/head
。
为此,我经常使用以下别名(如果PR已更新pr/ID
本地分支,则可以用于初始提取,然后用于后续获取):
$ git pr
Usage: git pr <id> [<remote>] # assuming <remote>[=origin] is on GitHub
$ git pr 101 # fetch PR #101 from origin -> branch pr/101
$ git pr 101 upstream # fetch PR #101 from upstream -> branch pr/101
免责声明:此定义不是命令的最后版本,请参见下面的
Further automation
。
下面是一行的定义,然后是一个扩展的表单:
$ git config --global alias.pr '!f() { if [ $# -lt 1 ]; then echo "Usage: git pr <id> [<remote>] # assuming <remote>[=origin] is on GitHub"; else git checkout -q "$(git rev-parse --verify HEAD)" && git fetch -fv "${2:-origin}" pull/"$1"/head:pr/"$1" && git checkout pr/"$1"; fi; }; f'
# git config --global alias.pr '!f() { if [ $# -lt 1 ]; then
echo "Usage: git pr <id> [<remote>] # assuming <remote>[=origin] is on GitHub";
else git checkout -q "$(git rev-parse --verify HEAD)" &&
git fetch -fv "${2:-origin}" pull/"$1"/head:pr/"$1" &&
git checkout pr/"$1";
fi; }; f'
但是,请注意,您不能直接推送到这些特殊分支。
如果您希望将PR (提交+强制推送)直接修改为维护器,则应该按照@yes-siz (提供的remote
)的建议,将叉添加为另一个公共关系提交人在打开公共关系时授权这种访问。。
进一步自动化
可以注意,上面的git pr
别名创建了一个只读分支,因为如果能够强制推到与PR关联的分支,就需要将其推送到源叉存储库中的特定分支(假设它的所有者授权了这个访问,如前所述)。
幸运的是,GitHub的REST API允许您轻松检索此信息( GitHub源存储库以及源引用),因此可以通过依赖简单的curl
调用和一些标准的Git命令(包括git branch --set-upstream-to
)来实现自动化。
把所有的东西放在一起,我们可以获得一些方便的Bash命令:
$ git prw
Facility to fetch a read/write branch from a GitHub repo Pull Request.
Usage:
git prw <ID> [<REMOTE>] [-f]
Example:
git prw 390 upstream
Summary:
If the REMOTE argument is omitted, it defaults to "origin".
REMOTE must point to a GitHub repository.
This command checkouts the branch named "pr/ID" (if it doesn't exist
yet, it fetches the source branch for the PR #ID in the REMOTE repo)
and sets its upstream branch so that one can force-push to the fork
(using an SSH URL); it reuses (if applicable) an existing remote
matching that URL, or creates a remote named REMOTE-fork-for-pr-ID.
Flag -f overwrites the local branch pr/ID even if it already exists.
In general, it is a good idea to pass flag -f, unless we already ran
"git pr ID REMOTE" and did commits in the local branch pr/ID.
It requires curl <https://curl.se/> and (optionally) jq.
See also:
- https://stackoverflow.com/a/62432946/9164010
- https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/checking-out-pull-requests-locally
- https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/allowing-changes-to-a-pull-request-branch-created-from-a-fork
发布于 2021-12-14 08:33:15
我的场景(接近,如果不是完全相同的话)是维护一个Github回购,其他人已经分叉,并提交PRs。下面是我审查分叉PRs的过程:
git remote add <forked-repo-org-or-name> <forked-repo-github-url>
检查是否添加了遥控器:
git remote -v
获取分叉回购的最新更新:
git fetch <forked-repo-org-or-name>
请查看分叉式公关分店:
git checkout <name-of-pr-branch>
现在,您可以在本地测试分支,探索并决定是否合并、注释等。
https://stackoverflow.com/questions/62432498
复制相似问题