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

推荐订阅源

S
Security Affairs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
Netflix TechBlog - Medium
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
A
About on SuperTechFans
Last Week in AI
Last Week in AI
博客园 - 叶小钗
博客园 - Franky
腾讯CDC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The GitHub Blog
The GitHub Blog
Google DeepMind News
Google DeepMind News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
小众软件
小众软件
The Hacker News
The Hacker News
C
Cisco Blogs
C
CXSECURITY Database RSS Feed - CXSecurity.com
L
LangChain Blog
WordPress大学
WordPress大学
美团技术团队
P
Proofpoint News Feed
T
Threat Research - Cisco Blogs
AWS News Blog
AWS News Blog
S
Securelist
T
Tenable Blog
I
Intezer
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
LINUX DO - 热门话题
博客园 - 三生石上(FineUI控件)
Y
Y Combinator Blog
Cisco Talos Blog
Cisco Talos Blog
T
Tor Project blog
Security Latest
Security Latest
Apple Machine Learning Research
Apple Machine Learning Research
C
Cybersecurity and Infrastructure Security Agency CISA
S
Schneier on Security
L
Lohrmann on Cybersecurity
P
Privacy & Cybersecurity Law Blog
月光博客
月光博客
P
Proofpoint News Feed
Vercel News
Vercel News
Simon Willison's Weblog
Simon Willison's Weblog
G
GRAHAM CLULEY
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
博客园 - 【当耐特】
A
Arctic Wolf
aimingoo的专栏
aimingoo的专栏

博客园 - 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,因为它保持独立仓库,更适合不同账户管理。