将GitHub拉取请求的旧版本视为远程分支 [英] See old versions of a GitHub pull request as remote branches

查看:90
本文介绍了将GitHub拉取请求的旧版本视为远程分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目中,该项目由Git维护,并在GitHub上有一个中央存储库.我经常在本地副本的帮助下审阅拉取请求.尽管Git本身对拉取请求"一无所知,但是GitHub在单独的分支命名空间中提供了这些信息.我已将Git配置为使用以下配置来获取拉取请求:

I am working on a project which is maintained in Git, with a central repository on GitHub. I often review pull requests with the help of a local copy. While Git itself doesn't know anything about "pull requests", GitHub makes the information available in a separate branch namespace. I've configured Git to fetch pull requests with a configuration like this:

[remote "origin"]
    url = git@github.com:octocat/hello-world.git
    fetch = +refs/heads/*:refs/remotes/origin
    fetch = +refs/pull/*/head:refs/remotes/origin/pull/head/*

然后我可以使用 git checkout origin/pull/head/42 检出PR#42.到目前为止一切顺利.

Then I can check out PR #42 with git checkout origin/pull/head/42. So far so good.

如果在初次审核后强行提出了拉取请求,我通常想将审核的版本与新版本进行比较.我想要类似 origin/pull/head/42/1 的内容,指的是第一次强制推送之前的最新提交, origin/pull/head/42/2 指的是第二次强制按下之前的最新提交,等等(我不介意确切的名称.)有什么方法可以做到这一点?

If a pull request has been force-pushed after my initial review, I often want to compare the version that I reviewed with the new version. I would like to have something like origin/pull/head/42/1 referring to the latest commit before the first force-push, origin/pull/head/42/2 referring to the latest commit before the second force-push, etc. (I don't mind the exact names.) Is there any way to do this?

问题有两个部分:

  1. 通过GitHub告诉我请求请求的pre-force-push提示的提交ID.此信息显示在网页上( https://github.com/octocal/hello-world/pull/42 说…从COMMIT1强制按下 mybranch 分支到COMMIT2"),但在 API .
  2. 告诉Git某个提交应该以某个远程分支名称出现,根据(1)的完成方式,它可能是微不足道的,也可能不是微不足道的.
  1. Get GitHub to tell me what the commit ID is for the pre-force-push tip of a pull request. This information appears on the web page (https://github.com/octocal/hello-world/pull/42 says "… force-pushed the mybranch branch from COMMIT1 to COMMIT2"), but I can't find it in the API.
  2. Teach Git that a certain commit should appear with a certain remote branch name, which may or may not be trivial depending on how (1) is done.

是否存在配置或帮助程序,可以使我轻松访问GitHub拉取请求的旧版本,而不必从网页中复制粘贴提交ID并为其指定本地分支名称?

Is there a configuration or helper program that can give me easy access to old versions of GitHub pull requests, without having to copy-paste the commit ID from the web page and give it a local branch name?

推荐答案

有一个事件API ,其中列出了在存储库中发生的操作并返回事件:

There is an Events API, which lists actions that occurred on a repo, and returns events :

  • 每个事件都有一个类型: PushEvent PullRequestEvent CreateEvent ...

和有效载荷,取决于其类型;例如:

and a payload, which depends on its type ; for example :

使用本地数据的部分答案:您的本地引用也记录在 reflog 中,您还可以查看git reflog origin/pull/head/42 代码>.

A partial answer with local data : your local refs are also logged in the reflog, you can also look at what you have in git reflog origin/pull/head/42.

很明显:该解决方案的局限性在于,您只能看到在本地仓库上运行 git fetch 的要点更新了该引用;如果有人在您的两个 git fetch 之间强行推了3次,则您的本地reflog将不会更新3次.

Obviously : the limitation of that solution is that you only see the points where running git fetch on your local repo updated that reference ; if someone has force pushed 3 times between two of your git fetch, your local reflog won't get updated 3 times.

这篇关于将GitHub拉取请求的旧版本视为远程分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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