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

推荐订阅源

Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
Schneier on Security
T
The Exploit Database - CXSecurity.com
K
Kaspersky official blog
Cisco Talos Blog
Cisco Talos Blog
P
Privacy International News Feed
T
Tenable Blog
T
Threat Research - Cisco Blogs
Spread Privacy
Spread Privacy
V
Vulnerabilities – Threatpost
L
LINUX DO - 热门话题
T
The Blog of Author Tim Ferriss
WordPress大学
WordPress大学
P
Proofpoint News Feed
宝玉的分享
宝玉的分享
月光博客
月光博客
美团技术团队
N
Netflix TechBlog - Medium
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
NISL@THU
NISL@THU
G
Google Developers Blog
P
Privacy & Cybersecurity Law Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
I
Intezer
C
Cyber Attacks, Cyber Crime and Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
MyScale Blog
MyScale Blog
C
CERT Recently Published Vulnerability Notes
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
Lohrmann on Cybersecurity
Recent Announcements
Recent Announcements
Project Zero
Project Zero
Latest news
Latest news
博客园_首页
C
Cisco Blogs
The Register - Security
The Register - Security
阮一峰的网络日志
阮一峰的网络日志
Simon Willison's Weblog
Simon Willison's Weblog
H
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AWS News Blog
AWS News Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
Docker
Vercel News
Vercel News
Know Your Adversary
Know Your Adversary
罗磊的独立博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
云风的 BLOG
云风的 BLOG

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