【问题标题】:How to update local checkedout PR code with the latest commits into PR?如何使用最新提交到 PR 更新本地签出 PR 代码?
【发布时间】:2020-04-26 16:28:04
【问题描述】:

我已将 PR 签入我的本地。现在 PR 更新了,如何使用最新的提交更新本地分支。 当我尝试做 git fetch upstream git pull origin 他们都说分支不存在。那是因为它是 PR 而不是分支。如何更新我的本地仓库?

【问题讨论】:

标签: git bitbucket git-pull git-fetch


【解决方案1】:

当您check out a PR locally 时,您正在获取特定命名空间中的分支:

git fetch origin pull/ID/head:BRANCHNAME
# or
git fetch upstream pull/ID/head:BRANCHNAME

但如果你执行 git config -l,你可能会看到如下设置:

remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*

与您的远程提取分支关联的 refspec,而不是 pull/branches

您需要添加(对于 GitHub 拉取请求):

fetch = +refs/pull/*/head:refs/remotes/origin/pr/* 

为了能够获取任何pr 分支。

对于BitBucket pull request

fetch = +refs/pull-requests/*/from:refs/remotes/upstream/pr/*

(提供BitBucket does refresh its PR branch

【讨论】:

    【解决方案2】:

    您可以通过以下方式更新/拉取已签出的未合并 PR 分支

    git pull upstream pull/PR-NUMBER/head:LOCAL-PR-BRANCH
    
    example : git pull upstream pull/352/head:pr-352
    

    仅供参考: 如何签出未合并的 PR:

    git fetch upstream pull/352/head:pr-352
    git checkout pr-352
    
    • 远程可以是上游或源
    • 352 是 PR 编号
    • pr-352 是 PR 签出的本地分支名称

    【讨论】:

      猜你喜欢
      • 2014-12-09
      • 2020-05-07
      • 1970-01-01
      • 2023-02-08
      • 1970-01-01
      • 2019-06-04
      • 2022-06-17
      • 1970-01-01
      • 2021-03-06
      相关资源
      最近更新 更多