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

推荐订阅源

量子位
Google DeepMind News
Google DeepMind News
爱范儿
爱范儿
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
NISL@THU
NISL@THU
T
Threat Research - Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
Lohrmann on Cybersecurity
V
Visual Studio Blog
Cyberwarzone
Cyberwarzone
D
Docker
The Hacker News
The Hacker News
C
CERT Recently Published Vulnerability Notes
Vercel News
Vercel News
Project Zero
Project Zero
S
Schneier on Security
aimingoo的专栏
aimingoo的专栏
I
Intezer
腾讯CDC
M
MIT News - Artificial intelligence
Hugging Face - Blog
Hugging Face - Blog
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
AWS News Blog
AWS News Blog
GbyAI
GbyAI
MongoDB | Blog
MongoDB | Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
Vulnerabilities – Threatpost
G
Google Developers Blog
N
Netflix TechBlog - Medium
The Cloudflare Blog
Microsoft Security Blog
Microsoft Security Blog
Y
Y Combinator Blog
A
Arctic Wolf
S
Securelist
酷 壳 – CoolShell
酷 壳 – CoolShell
Cisco Talos Blog
Cisco Talos Blog
Recent Announcements
Recent Announcements
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LINUX DO - 热门话题
T
Threatpost
Latest news
Latest news
Blog — PlanetScale
Blog — PlanetScale
Security Latest
Security Latest
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
H
Help Net Security
The GitHub Blog
The GitHub Blog
T
Tor Project blog
P
Proofpoint News Feed

博客园 - wjwdive

MAC多github账号配置步骤 记录一次flutter boost5.0.2示例调试的过程 【算法】可获得的最大点数问题 使用1panel一键建站 关于混合加密(AES+RSA) C++设计模式汇总 设计模式C++005__桥模式 设计模式C++007__抽象工厂方法模式 设计模式C++004__装饰器模式 设计模式C++003__观察者模式 设计模式C++002__策略模式 设计模式C++001__模板方法 使用bundler自动化构建Xcode项目时遇到的问题。 AI图片生成网站 suno AI编曲创作利器 iOS组件化开发之私有库 iOS、Android获取apk公钥MD5信息 阿里图标库批量下载iOS适配的图标 C语言实现回调函数标准方式 swift 自定义tabbar为基本结构的项目 swift 可选类型
如何使用git submodule拆分大的git项目
wjwdive · 2026-04-29 · via 博客园 - wjwdive

背景

我开发一个全栈项目,起初为了让AI统一同时开发前端,后端,客户端。将项目放在了同一个目录下用git统一管理。

例如:

myProjects:

--FrontEnd,

--BackEnd,

--Client

后来基础架构搭建完成,我需要将三个项目目录分别模块化。

如何处理,每种方案进行前务必先将项目copy一份哦

方案1、Git Submodule(推荐)

原来的git管理的项目使用一个总库,将FrontEnd单独做一个submodule。

 方案1:Git Submodule(推荐)                                                                                                                             
  # 1. 创建独立的 frontend 仓库                                                                                                                            
  cd /path/to/new/location                                                                                                                                 
  git init frontend-repo                                                                                                                                   
  cp -r /path/to/myProjects/frontend/* .                                                                                 
  git add .                                                                                                                                                
  git commit -m "Initial frontend commit"                                                                                                                  
  git remote add origin <frontend-repo-url>                                                                                                                
  git push -u origin main       
 # 2. 在主项目中移除 frontend 并添加为 submodule                                                                                                          
  cd /path/to/myProjects/                                                                           
  git rm -r frontend                                                                                                                                       
  git commit -m "Remove frontend for submodule conversion"                                                                                                 
  git submodule add <frontend-repo-url> frontend                                                                                                           
  git commit -m "Add frontend as submodule"     

方案2 Git Subtree(更简单)

# 1. 先提取 frontend 历史到独立分支                                                                                                                      
  git subtree split --prefix=frontend -b frontend-only 
 # 2. 创建新仓库并推送                                                                                                                                    
  mkdir ../frontend-repo && cd ../frontend-repo                                                                                                            
  git init                                                                                                                                                 
  git pull ../myProjects frontend-only                                                                                                                     
  git remote add origin <frontend-repo-url>                                                                                                                
  git push -u origin main   
  # 3. 回到主项目,移除并添加为 subtree                                                                                                                    
  cd ../myProjects                                                                                                                                         
  git rm -r frontend                                                                                                                                       
  git commit -m "Remove frontend for subtree"                                                                                                              
  git subtree add --prefix=frontend <frontend-repo-url> main                                                                                               
       

配置不同 Git 账户:

# 在 frontend 子项目中                                                                                                                                   
  cd frontend                                                                                                                                              
  git config user.name "Frontend Developer"                                                                                                                
  git config user.email "frontend@example.com"                                                                                                             

推荐 Submodule,因为它保持独立仓库,更适合不同账户管理。