Github 上有些项目可能作者长时间没有进行维护, 会出现有些新的 pr 没有合并到主分支 master 上. 这时如果想在本地应用这个新的 pr 呢? 一般来说主要有以下几种方式:
- 针对提交的
pr, 查看具体的改动文件和改动内容, 然后在本地进行对应的修改. - 通过
git merge或git cherry-pick进行合并.
手动修改 PR 内容
以 github 上的 w3m 为例, 查看 pull requests 列表如下:
![1642058854087)(images/pull_requests.png)]](https://i-blog.csdnimg.cn/blog_migrate/70d5e4bcbc0a872548b3ba2930d158e8.png)
我们选择最后一个比较简单的 PR 进行查看, 点击 Files changed 查看文件具体的变更信息.
![1642058854091)(images/files_changed.png)]](https://i-blog.csdnimg.cn/blog_migrate/24603731d0ca6f3070c9249200884c43.png)
根据文件的具体变更信息, 对应的在本地进行相应的修改. 这种方式只适合改变很少的 PR. 如果 PR 的信息量比较大的时候, 那就不适合了. (除非非常喜欢手工活☴ )
通过 Git 命令合并
首先我们通过 git clone 把对应的仓库下载到本地. 通过以下命令可以查看远程仓库为 origin, 这也时克隆后默认提供的远程仓库名称.
➜ w3m git:(master) ✗ git remote -v
origin https://github.com/tats/w3m (fetch)
origin https://github.com/tats/w3m (push)
接着我们通过 PR 中的信息, 找到具体的 PR 提供者的仓库, 并复制其仓库地址.
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-iUMUQ8Up-1642058854098)(images/fork_repositoty_url.png)]](https://i-blog.csdnimg.cn/blog_migrate/45c0ab611c20ae9ab7bf5925e65a0cfd.png)
通过命令 git remote add 远程仓库名 远程仓库地址 增加新的远程仓库信息.
➜ w3m git:(master) ✗ git remote add testpr1 https://github.com/ctrlcctrlv/w3m.git
➜ w3m git:(master) ✗ git remote -v
origin https://github.com/tats/w3m (fetch)
origin https://github.com/tats/w3m (push)
testpr1 https://github.com/ctrlcctrlv/w3m.git (fetch)
testpr1 https://github.com/ctrlcctrlv/w3m.git (push)
仓库增加成功后, 通过 git fetch 仓库名 把新加的远程仓储代码下载到本地.
➜ w3m git:(master) ✗ git fetch testpr1
remote: Enumerating objects: 9074, done.
remote: Counting objects: 100% (4961/4961), done.
remote: Compressing objects: 100% (144/144), done.
最后通过 merge 或 cherry-pick 合并整个分支或者某个具体的提交. 下面是如何查看具体的分支和 commitid 信息.
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-4uZPucW4-1642058854110)(images/commitid_and_branch.png)]](https://i-blog.csdnimg.cn/blog_migrate/ec31254d46fc1a22137abfdaf1176d27.png)
# 合并具体的 commitid
➜ w3m git:(master) ✗ git cherry-pick 12eac50d44f7c02987a78b7f4d55477370afc1b1
[master e87730b] Use libsixel fork with CVE fixes
Author: Fredrick Brennan <copypaste@kittens.ph>
Date: Sat Jun 12 21:49:02 2021 -0400
1 file changed, 1 insertion(+), 1 deletion(-)
# 合并具体的分支
➜ w3m git:(master) git merge testpr1/patch-1
当我们合并完相关的 PR 时, 可以通过 git remote rm 仓库名 进行清理 PR 远程仓库的相关信息.
➜ w3m git:(master) git remote rm testpr1
➜ w3m git:(master)
当GitHub项目中有人提交的PR未被合并,如何在本地应用这些更改?可以通过查看PR的改动并手动修改,或者使用git命令进行合并。手动修改适用于少量更改,大量更改则推荐使用git命令。首先,通过git clone获取仓库,然后添加PR提供者的远程仓库,拉取代码,再用git merge或git cherry-pick合并。合并后,可以清理远程仓库信息。
425

被折叠的 条评论
为什么被折叠?



