起因
之前,我写过一篇文章:在GitHub上fork项目后,如何与原仓库同步?图解全过程,介绍如何在自己fork的项目里跟随原仓库进行同步更新。
按照这个方法提交的PR是这样的:
可以看到有一些和本次PR无关的提交日志,终于这次被大佬质疑了:
面对大佬的质疑,像我这样优(mí)秀(máng)的人,像我这样聪(xún)明(zhǎo)的人,当然是马上这样回复了:
我必须推翻之前的我自己写文章,虽然啪啪啪低打了自己的脸,但也要立正站好。
终极解决办法
经过我的刻苦学习git知识,我终于找到了终极解决方案,下面以我实际的项目为例,给小伙伴们展示一下。
- 先把我自己 fork 的 skywalking 项目克隆到本地:
git clone https://github.com/heihaozi/skywalking.git skywalking
输出如下:
Cloning into 'skywalking'...
remote: Enumerating objects: 232380, done.
remote: Counting objects: 100% (416/416), done.
remote: Compressing objects: 100% (228/228), done.
remote: Total 232380 (delta 119), reused 327 (delta 71), pack-reused 231964
Receiving objects: 100% (232380/232380), 155.35 MiB | 7.12 MiB/s, done.
Resolving deltas: 100% (89444/89444), done.
Updating files: 100% (5790/5790), done.
- 进入克隆的本地目录,把 skywalking 官方地址添加为远程仓库,我们叫它upstream:
git remote add upstream https://github.com/apache/skywalking.git
查看是否添加成功:
git remote -v
输出如下:
origin https://github.com/heihaozi/skywalking.git (fetch)
origin https://github.com/heihaozi/skywalking.git (push)
upstream https://github.com/apache/skywalking.git (fetch)
upstream https://github.com/apache/skywalking.git (push)
说明已经添加成功了。
- 从远程仓库upstream获取所有更新。
git fetch upstream
输出如下:
remote: Enumerating objects: 344, done.
remote: Counting objects: 100% (344/344), done.
remote: Compressing objects: 100% (83/83), done.
remote: Total 225 (delta 99), reused 185 (delta 68), pack-reused 0
Receiving objects: 100% (225/225), 32.78 KiB | 1.82 MiB/s, done.
Resolving deltas: 100% (99/99), completed with 67 local objects.
From https://github.com/apache/skywalking* [new branch] 5.x -> upstream/5.x* [new branch] 6.x -> upstream/6.x* [new branch] feature/2.x -> upstream/feature/2.x* [new branch] feature/3.0.x -> upstream/feature/3.0.x* [new branch] feature/3.1.x -> upstream/feature/3.1.x* [new branch] master -> upstream/master* [new branch] website-docs/8.2.0 -> upstream/website-docs/8.2.0* [new branch] website-docs/8.3.0 -> upstream/website-docs/8.3.0* [new branch] website-docs/8.4.0 -> upstream/website-docs/8.4.0* [new branch] zipkin -> upstream/zipkin
- 确保分支在主干上:
git checkout master
- 重写主干的历史纪录:
git rebase upstream/master
输出如下:
Successfully rebased and updated refs/heads/master.
- 强制推送到 GitHub 上的远程仓库:
git push -f origin master
输出如下:
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/heihaozi/skywalking.git17fffe8e1..3b15f8d13 master -> master
至此,大功告成!
在文章最后求赞,有些人可能会想,求赞狗我才不点,我就要白嫖;而有些人则很 nice,花了几秒钟,点赞收藏评论一气呵成。
可能这随手的一键三连,就让我们成为了朋友,以后他有什么工作或职场的问题,我可以给出一些有用的建议。