【问题标题】:How can I view the pull request URL for the current branch?如何查看当前分支的拉取请求 URL?
【发布时间】:2018-08-17 09:24:16
【问题描述】:

推送更改后,我看到如下文本:

Writing objects: 100% (5/5), 478 bytes | 239.00 KiB/s, done.
Total 5 (delta 4), reused 0 (delta 0)
remote:
remote: Create pull request for my-branch => master-branch
remote:   https://bitbucket.org/my-company/repo/pull-requests/12345

但是,如果我当时不进行 PR,并且文本滚动到视野之外,那么那个 URL 就消失了。如何在不进行更改和再次提交/推送的情况下简单地生成或重新查看该 URL?

【问题讨论】:

    标签: git bitbucket pull-request


    【解决方案1】:

    要使用网络浏览器(bitbucket 网络界面)创建拉取请求,请转到您的分支的 branch 网页,或您的 bitbucket 存储库的 branches 页面。

    使用问题中的示例:

    remote: Create pull request for my-branch => master-branch
    remote:   https://bitbucket.org/my-company/repo/pull-requests/12345
    

    我们可以去 https://bitbucket.org/my-company/repo/branch/my-branch,有一个“创建拉取请求”链接。

    或者我们可以去 https://bitbucket.org/my-company/repo/branches, 有一个名为“拉取请求”的列,对于没有现有拉取请求的分支,有一个“创建”链接。

    【讨论】:

      【解决方案2】:

      Bash 版本:

      #!/bin/bash
      
      org="myOrg"
      branch=$(git rev-parse --abbrev-ref HEAD)
      repo_dir=$(git rev-parse --show-toplevel)
      repo=$(basename ${repo_dir})
      url="https://bitbucket.org/${org}/${repo}/pull-requests/new?source=${branch}&t=1"
      
      echo $url
      

      【讨论】:

        【解决方案3】:

        我能够使用这样的批处理文件生成 URL:

        @echo off
        
        setlocal 
        for /f "tokens=*" %%a in ( 
            'git rev-parse --abbrev-ref HEAD'
        ) do ( 
            set branch=%%a
            set url=https://bitbucket.org/my-company/repo/pull-requests/new?source=%%a^^^&t=1
        ) 
        
        echo %url%
        endlocal 
        

        它只是抓取当前的 git 分支并放入一个字符串,然后回显该字符串。

        【讨论】:

        • 你可以稍微复杂一点:alias pr_url="https://bitbucket.org/$(git remote -v | head -n 1 | grep -oP '[\w+_]+\/[\w+_]+')/pull-requests/new?source=$(git branch --show-current)"
        【解决方案4】:

        此拉取请求 URL 不是 git 功能,而是由 BitBucket 服务器上的钩子脚本生成的消息。

        在 BitBucket 服务器上,您可以使用以下命令全局禁用它:How do I disable the remote create pull request message when pushing changes?。在 BitBucket 云上,您无法禁用它。

        获得此消息的一种方法是使用--dry-run 选项模拟git pull,例如:

        git pull --dry-run 
        

        但如果这还不足以触发钩子,可能唯一的方法就是通过 BitBucket 网络界面。

        【讨论】:

        • 那不是 Bitbucket Server - 那是 Bitbucket Cloud。
        【解决方案5】:

        您在此处列出的 URL 用于已经存在的拉取请求 - “查看拉取请求”文本是那里的赠品。现有的拉取请求在 URL 中有一个 ID,您需要指定它;如果您不知道 ID,则需要从 GUI 获取 URL(https://bitbucket.org/owner/repo/pull-requests/ 可能是最容易找到它的地方)。

        如果您的分支还没有拉取请求,那么钩子生成的“创建拉取请求”链接是https://bitbucket.org/owner/repo/pull-requests/new?source=branchname&t=1

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-01-31
          • 2021-04-06
          • 1970-01-01
          • 2020-02-20
          • 1970-01-01
          • 1970-01-01
          • 2015-02-18
          相关资源
          最近更新 更多