本篇笔记核心: 如何保持自己的仓库与作者的更新?
克隆自己的远程仓库
git clone <自己的仓库链接>
git remote -v
看一下可知链接名默认为origin
链接作者远程仓库
git remote add <连接名> <作者的仓库链接>
这里起名为upstream
然后再次 git remote -v 查看可知所有链接仓库
Administrator@WIN-6VE9JU0V0LN MINGW64 ~/Desktop/新建文件夹/Oblog (v4)
$ git remote add upstream https://github.com/jackyzha0/quartz.git
Administrator@WIN-6VE9JU0V0LN MINGW64 ~/Desktop/新建文件夹/Oblog (v4)
$ git remote -v
origin https://github.com/Halecoder/Oblog.git (fetch)
origin https://github.com/Halecoder/Oblog.git (push)
upstream https://github.com/jackyzha0/quartz.git (fetch)
upstream https://github.com/jackyzha0/quartz.git (push)
拉取要更新的分支到自己分支
git fetcn <连接名> <别人分支>:<新建分支>
git fetch upstream v4:dev
意味着将作者分支v4拉取到本地分支dev,dev会自动创建
参考: git更新远程代码到本地仓库的命令_習慣-學習的博客-CSDN博客
合并分支
git merge <分支名>
表示将dev分支合并到本分支下
$ git merge dev --allow-unrelated-histories
Auto-merging .github/workflows/ci.yaml
CONFLICT (add/add): Merge conflict in .github/workflows/ci.yaml
CONFLICT (file/directory): directory in the way of content from HEAD; moving it to content~HEAD instead.
Auto-merging docs/index.md
CONFLICT (add/add): Merge conflict in docs/index.md
Auto-merging package-lock.json
CONFLICT (add/add): Merge conflict in package-lock.json
Auto-merging package.json
CONFLICT (add/add): Merge conflict in package.json
Auto-merging quartz.config.ts
CONFLICT (add/add): Merge conflict in quartz.config.ts
Auto-merging quartz.layout.ts
CONFLICT (add/add): Merge conflict in quartz.layout.ts
CONFLICT (add/add): Merge conflict in quartz/bootstrap-cli.mjs
Auto-merging quartz/components/Graph.tsx
CONFLICT (add/add): Merge conflict in quartz/components/Graph.tsx
Auto-merging quartz/components/Head.tsx
CONFLICT (add/add): Merge conflict in quartz/components/Head.tsx
Auto-merging quartz/components/index.ts
CONFLICT (add/add): Merge conflict in quartz/components/index.ts
Auto-merging quartz/components/renderPage.tsx
CONFLICT (add/add): Merge conflict in quartz/components/renderPage.tsx
Auto-merging quartz/components/scripts/graph.inline.ts
CONFLICT (add/add): Merge conflict in quartz/components/scripts/graph.inline.ts
Auto-merging quartz/plugins/emitters/404.tsx
CONFLICT (add/add): Merge conflict in quartz/plugins/emitters/404.tsx
Auto-merging quartz/plugins/emitters/contentIndex.ts
CONFLICT (add/add): Merge conflict in quartz/plugins/emitters/contentIndex.ts
Auto-merging quartz/plugins/emitters/contentPage.tsx
CONFLICT (add/add): Merge conflict in quartz/plugins/emitters/contentPage.tsx
Auto-merging quartz/plugins/emitters/folderPage.tsx
CONFLICT (add/add): Merge conflict in quartz/plugins/emitters/folderPage.tsx
Auto-merging quartz/plugins/emitters/tagPage.tsx
CONFLICT (add/add): Merge conflict in quartz/plugins/emitters/tagPage.tsx
Auto-merging quartz/plugins/transformers/index.ts
CONFLICT (add/add): Merge conflict in quartz/plugins/transformers/index.ts
Auto-merging quartz/plugins/transformers/lastmod.ts
CONFLICT (add/add): Merge conflict in quartz/plugins/transformers/lastmod.ts
Auto-merging quartz/plugins/transformers/latex.ts
CONFLICT (add/add): **Merge conflict** in quartz/plugins/transformers/latex.ts
Auto-merging quartz/plugins/transformers/links.ts
CONFLICT (add/add): Merge conflict in quartz/plugins/transformers/links.ts
Auto-merging quartz/plugins/transformers/ofm.ts
CONFLICT (add/add): Merge conflict in quartz/plugins/transformers/ofm.ts
Auto-merging quartz/styles/base.scss
CONFLICT (add/add): Merge conflict in quartz/styles/base.scss
Auto-merging quartz/util/path.ts
CONFLICT (add/add): Merge conflict in quartz/util/path.ts
Automatic merge failed; fix conflicts and then commit the result.
Merge conflict 表示产生合并冲突,需要解决
拓展:
记 Git 报错 - refusing to merge unrelated histories
终于弄明白 git fetch 和 git pull 区别
打开Vsccode编辑器,解决冲突
最后提交
注意是提交到自己仓库,而不是作者仓库,前面连接名有origin和upstream
origin: 自己本地的远程仓库 upstream: 作者本人的远程仓库
提交到自己的: git push origin v4
参考:
【Git】如何把别人仓库里面的代码更新到自己的远程仓库上来(无冲突的前提下)
更新完成之后即可删除分支