惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
T
Threatpost
WordPress大学
WordPress大学
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
PCI Perspectives
PCI Perspectives
T
The Exploit Database - CXSecurity.com
Y
Y Combinator Blog
雷峰网
雷峰网
爱范儿
爱范儿
The Hacker News
The Hacker News
Last Week in AI
Last Week in AI
Simon Willison's Weblog
Simon Willison's Weblog
T
Tor Project blog
S
Securelist
宝玉的分享
宝玉的分享
L
LangChain Blog
O
OpenAI News
AI
AI
P
Privacy International News Feed
L
LINUX DO - 最新话题
D
DataBreaches.Net
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs
罗磊的独立博客
M
MIT News - Artificial intelligence
Security Archives - TechRepublic
Security Archives - TechRepublic
月光博客
月光博客
博客园 - 【当耐特】
T
Tailwind CSS Blog
C
Cybersecurity and Infrastructure Security Agency CISA
H
Help Net Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园_首页
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Hacker News - Newest:
Hacker News - Newest: "LLM"
腾讯CDC
Jina AI
Jina AI
The Last Watchdog
The Last Watchdog
K
Kaspersky official blog
Webroot Blog
Webroot Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Blog — PlanetScale
Blog — PlanetScale
MyScale Blog
MyScale Blog
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
Recorded Future
Recorded Future
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 三生石上(FineUI控件)
The Cloudflare Blog

记录点滴 – 魔帆博客

Python包管理的血泪史:从混乱到秩序的漫长征 | 魔帆博客 日文中的衬线、非衬线混排 | 魔帆博客 网页排版中的字体衬线 | 魔帆博客 Git配置:如何优雅的配置多用户并使用 ssh 密钥验证 | 魔帆博客 【记录】使用Golang开发腾讯云函数踩的坑 | 魔帆博客 Git 提示 fatal: unsafe repository is owned by someone else 错误 | 魔帆博客 【笔记】Hydro二次开发总结 前端篇(一) | 魔帆博客 C/C++ 二叉树 | 魔帆博客 Linux 报错Certificate verification failed: The certificate is NOT trusted. | 魔帆博客 Python 数字大小写转换 | 魔帆博客 Windows10 系统盘开启 Bitlocker | 魔帆博客 Docker WSL1/2 迁移 Linux 发行版目录 | 魔帆博客 中兴 CPE (4G) 设置 IPv6 联网 | 魔帆博客 VS Code C/C++ 环境配置 | 魔帆博客 使用 Excel 在地图上标注城市 | 魔帆博客 替换 PHP creat_function() 函数 | 魔帆博客 天下大事,尽在其中——德生 R-9012 收音机 | 魔帆博客 【技巧】干掉第三方抢票!如何以最快的速度抢到火车票 | 魔帆博客 【记录】Deepin 桌面无限转圈(风火轮) | 魔帆博客
Git 合并本地两个不同的 Repo 仓库 | 魔帆博客
野小新 · 2022-05-07 · via 记录点滴 – 魔帆博客

今天整理电脑资料的时候发现有两个本地仓库需要整合到一起,所以记录一下如何处理这种情况。

Git 仓库因为有历史记录,合并时候最好不要直接直接复制文件,最好能够保留历史记录让两个仓库合并到一起。

其实这个步骤和git tempale / upstream 同步方法基本上是一样的,就是先添加一个远程的地址然后把它拉取下来,以此创建一个分支然后处理冲突并合并。

只是我们要合并的这两个仓库不能说是没什么关系,只能说是毫不相关。因此基本上不需要解决冲突。

合并两个 Git 本地仓库

首先这里有两个仓库

  • 学金采访
  • 宣传邮件

我们要把宣传邮件这个仓库合并到学金采访里

首先进入 学金采访 仓库,可以看到 remote 只有一个 origin。

学金采访 on  master
❯ git remote -v
origin  git@github.com:MorFans/China-scholarship-interview-answer.git (fetch)
origin  git@github.com:MorFans/China-scholarship-interview-answer.git (push)

要把 宣传邮件合并到 学金采访 仓库中,我们先把 宣传邮件 仓库设置为它的remote,这里取名为 merge_branch:

这里 ..\宣传邮件\宣传邮件 仓库的路径,如果你是远程,把这里改成网址即可(确保你有访问权)

学金采访 on  master
❯ git remote add merge_branch ..\宣传邮件\

添加完成后,可以看到已经多出来了 merge_branch:

学金采访 on  master
❯ git remote -v  
merge_branch    ..\奖学金\ (fetch)
merge_branch    ..\奖学金\ (push)
origin  git@github.com:MorFans/China-scholarship-interview-answer.git (fetch)
origin  git@github.com:MorFans/China-scholarship-interview-answer.git (push)

然后我们把 宣传邮件 仓库给拉取下来:

fetch 之后会就有了这个 merge_branch/master 分支,这个就是我们的 宣传邮件 仓库的

学金采访 on  master
❯ git branch -a
*master
remotes/origin/master

学金采访 on  master
❯ git fetch merge_branch
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 6 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), 2.46 KiB | 148.00 KiB/s, done.
From ..\宣传邮件\
 * [new branch]      master     -> merge_branch/master

然后以此创建一个分支 merge

学金采访 on  master
❯ git checkout -b merge merge_branch/master
Switched to a new branch 'merge'

branch 'merge' set up to track 'merge_branch/master'.

然后就可以合并了,先切换到 主分支(master),然后把 merge 分支合并到 master 分支

使用 git merge 命令,配上允许不相关历史参数来合并:

学金采访 on  merge:master
❯ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

学金采访 on  master
❯ git merge --allow-unrelated-histories merge
Merge made by the 'ort' strategy.

 ...邮件.txt" | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 "邮件.txt"

至此就合并完成了 🎉