使用案例:我在GitHub上有一些回购,有人将它分叉并添加了新功能并启动了拉取请求。 我不能自动合并它,因为我想先解决一些小问题。
这是一次性活动,我永远不需要这个远程存储库,因此我不想创建本地remote
分支。
基本上我想做:
怎么做?
git checkout git://github.com/xxx/xxx.git
根本不起作用(失败并出错)
git fetch git://github.com/xxx/xxx.git
有效,但不会更新任何内容
答案 0 :(得分:13)
您想使用FETCH_HEAD
。
无论何时运行git fetch ...
,都会创建名为FETCH_HEAD
的魔术引用。
试着举例:
git fetch git://github.com/xxx/xxx.git branch_name && git merge FETCH_HEAD
答案 1 :(得分:12)
对于任何Git服务器:
git fetch git://host.com/path/to/repo.git remote-branch-name:local-branch-name
git checkout local-branch-name
答案 2 :(得分:6)
另一个简洁的方法(至少在Github上/来自Github)是这样的:
git fetch repo pull/7324/head:pr-7324
其中:
repo
指向远程仓库,例如git://github.com/xxx/xxx.git
。
pull/7324/head
是远程拉取请求。
pr-7324
是本地拉取请求分支。
然后你可以使用本地PR分支随你做任何你想做的事。
来源:改编自this discussion。