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

推荐订阅源

L
LangChain Blog
N
Netflix TechBlog - Medium
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
V2EX
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Blog — PlanetScale
Blog — PlanetScale
Microsoft Security Blog
Microsoft Security Blog
D
Docker
WordPress大学
WordPress大学
罗磊的独立博客
J
Java Code Geeks
博客园 - 【当耐特】
博客园 - 司徒正美
雷峰网
雷峰网
H
Help Net Security
酷 壳 – CoolShell
酷 壳 – CoolShell
Last Week in AI
Last Week in AI
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
T
Tailwind CSS Blog
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence
Recent Announcements
Recent Announcements
B
Blog

博客园 - wjwdive

Apple官方package介绍 SwiftUI常用的第三方package MAC安装鼠尾管输入引擎并配置雾凇词库+万象拼音大模型 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,因为它保持独立仓库,更适合不同账户管理。