# demo-java **Repository Path**: zerocn/demo-java ## Basic Information - **Project Name**: demo-java - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-05-08 - **Last Updated**: 2025-01-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Git SubModule * help ```git git submodule --h git submodule --help ``` * commands ```git git submodule [--quiet] [--cached] git submodule [--quiet] add [-b ] [-f|--force] [--name ] [--reference ] [--] [] git submodule [--quiet] status [--cached] [--recursive] [--] [...] git submodule [--quiet] init [--] [...] git submodule [--quiet] deinit [-f|--force] (--all| [--] ...) git submodule [--quiet] update [--init [--filter=]] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference ] [--recursive] [--[no-]single-branch] [--] [...] git submodule [--quiet] set-branch (--default|--branch ) [--] git submodule [--quiet] set-url [--] git submodule [--quiet] summary [--cached|--files] [--summary-limit ] [commit] [--] [...] git submodule [--quiet] foreach [--recursive] git submodule [--quiet] sync [--recursive] [--] [...] git submodule [--quiet] absorbgitdirs [--] [...] ``` ## 新增子模块 ```git git submodule add -b main https://gitee.com/zerocn/submodule-name.git submodule-name ``` ## 更新子模块 ```git git submodule update --remote --recursive ``` ## 首次更新子模块 ```git git submodule update --init --recursive --remote git submodule foreach -q --recursive 'git checkout $(git config -f $toplevel/.gitmodules submodule.$name.branch || echo master)' ``` ## 重命名子模块 ### 1、更新子模块文件夹名称 ```git git mv --cached old-name new-name ``` ### 2、编辑 .gitmodules 文件 打开 .gitmodules 文件,找到想要重命名的子模块相关的部分。修改 path 和 url (如果需要的话)。 ### 3、更新父仓库的 Git 配置 在 .git/config 文件中,可能会有关于子模块的配置信息,如果有,也需要做相应的修改。 ### 4、提交更改 ```git git add .gitmodules git commit -m "Rename submodule from 'old-name' to 'new-name'" ``` ### 5、更新子模块引用 ```git git submodule sync git submodule update --recursive ``` ## 删除子模块 ### 1、把子模块从 VCS 中移除 ```git git rm --cached submodule-dir ``` ### 2、删除子模块目录 ```git # Linux/macOS rm -rf submodule-dir # Windows PowerShell Remove-Item -Recurse -Force submodule-dir # Windows CMD RD /S /Q submodule-dir ``` ### 3、删除子模块相关的未跟踪文件 ```git # Linux/macOS rm -rf .git/modules/submodule-name # Windows PowerShell Remove-Item -Recurse -Force .git\modules\submodule-name # Windows CMD RD /S /Q .git\modules\submodule-name ``` ### 4、从 .gitmodules 文件中移除子模块配置 ```git git config --file=.gitmodules --remove-section submodule.submodule-name ``` ### 5、从 .git/config 文件中删除子模块的相关条目 ```git git config --remove-section submodule.submodule-name ``` ### 6、提交更改 ```git git commit -m "Remove submodule 'submodule-name'" ```