Git: Add submodule with a specific version

本文介绍如何使用Git子模块来添加并锁定STM32标准库的具体版本,包括初始化子模块、更新以及重置到指定版本的过程。

Add submodule with a specific version:

git submodule add git://github.com/XXXXX/xxx.yyyy.git stm32_std_lib
git status

git submodule init
git submodule update

cd stm32_std_lib/
git reset --hard V3.1.2 
cd ..
git commit -a

git submodule status

(rtx5070_env) PS E:\PyTorch_Build\pytorch> git submodule update --init --recursive# 清理特定版本目录(v2.1.0) usage: git submodule [--quiet] [--cached] or: git submodule [--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--] <repository> [<path>] or: git submodule [--quiet] status [--cached] [--recursive] [--] [<path>...] or: git submodule [--quiet] init [--] [<path>...] or: git submodule [--quiet] deinit [-f|--force] (--all| [--] <path>...) or: git submodule [--quiet] update [--init [--filter=<filter-spec>]] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--[no-]single-branch] [--] [<path>...] or: git submodule [--quiet] set-branch (--default|--branch <branch>) [--] <path> or: git submodule [--quiet] set-url [--] <path> <newurl> or: git submodule [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...] or: git submodule [--quiet] foreach [--recursive] <command> or: git submodule [--quiet] sync [--recursive] [--] [<path>...] or: git submodule [--quiet] absorbgitdirs [--] [<path>...] (rtx5070_env) PS E:\PyTorch_Build\pytorch> $targetDir = "E:\PyTorch_Build\pytorch\pytorch-2.1.0" (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> if (Test-Path $targetDir) { >> # 递归删除目录(包括隐藏文件) >> Remove-Item -Path $targetDir -Recurse -Force -Confirm:$false >> >> # 检查删除结果 >> if (-not (Test-Path $targetDir)) { >> Write-Host "✅ 已成功清理 PyTorch v2.1.0 目录" -ForegroundColor Green >> } else { >> Write-Host "❌ 清理失败,请手动删除" -ForegroundColor Red >> explorer.exe /select,$targetDir >> } >> } else { >> Write-Host "ℹ️ 目录不存在: $targetDir" -ForegroundColor Cyan >> } ℹ️ 目录不存在: E:\PyTorch_Build\pytorch\pytorch-2.1.0 (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 清理 Git 临时文件(防止残留) (rtx5070_env) PS E:\PyTorch_Build\pytorch> $gitTempFiles = @( >> "$PWD\.git\objects\pack\tmp_pack_*", >> "$PWD\.git\index.lock", >> "$PWD\.git\shallow.lock" >> ) (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> Get-Item -Path $gitTempFiles -ErrorAction SilentlyContinue | Remove-Item -Force (rtx5070_env) PS E:\PyTorch_Build\pytorch> Write-Host "✅ Git 临时文件已清理" -ForegroundColor Green ✅ Git 临时文件已清理 (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 清理特定版本目录(v2.1.0) (rtx5070_env) PS E:\PyTorch_Build\pytorch> $targetDir = "E:\PyTorch_Build\pytorch\pytorch-2.1.0" (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> if (Test-Path $targetDir) { >> # 递归删除目录(包括隐藏文件) >> Remove-Item -Path $targetDir -Recurse -Force -Confirm:$false >> >> # 检查删除结果 >> if (-not (Test-Path $targetDir)) { >> Write-Host "✅ 已成功清理 PyTorch v2.1.0 目录" -ForegroundColor Green >> } else { >> Write-Host "❌ 清理失败,请手动删除" -ForegroundColor Red >> explorer.exe /select,$targetDir >> } >> } else { >> Write-Host "ℹ️ 目录不存在: $targetDir" -ForegroundColor Cyan >> } ℹ️ 目录不存在: E:\PyTorch_Build\pytorch\pytorch-2.1.0 (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 清理 Git 临时文件(防止残留) (rtx5070_env) PS E:\PyTorch_Build\pytorch> $gitTempFiles = @( >> "$PWD\.git\objects\pack\tmp_pack_*", >> "$PWD\.git\index.lock", >> "$PWD\.git\shallow.lock" >> ) (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> Get-Item -Path $gitTempFiles -ErrorAction SilentlyContinue | Remove-Item -Force (rtx5070_env) PS E:\PyTorch_Build\pytorch> Write-Host "✅ Git 临时文件已清理" -ForegroundColor Green ✅ Git 临时文件已清理 (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 获取清理后的磁盘空间状态 (rtx5070_env) PS E:\PyTorch_Build\pytorch> $drive = (Get-Item $PWD).PSDrive.Name (rtx5070_env) PS E:\PyTorch_Build\pytorch> $diskInfo = Get-PSDrive -Name $drive | >> Select-Object Used,Free,@{Name="Size(GB)";Expression={[math]::Round($_.Used/1GB,2)}} (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> Write-Host "磁盘空间报告:" -ForegroundColor Yellow 磁盘空间报告: (rtx5070_env) PS E:\PyTorch_Build\pytorch> Write-Host "已用空间: $($diskInfo.Used/1GB) GB" -ForegroundColor Cyan 已用空间: 462.449703216553 GB (rtx5070_env) PS E:\PyTorch_Build\pytorch> Write-Host "可用空间: $($diskInfo.Free/1GB) GB" -ForegroundColor Green 可用空间: 3352.98095703125 GB (rtx5070_env) PS E:\PyTorch_Build\pytorch> param( >> [string]$ClonePath = "E:\PyTorch_Build\pytorch\pytorch-2.1.0" >> ) (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 1. 终止所有相关进程 (rtx5070_env) PS E:\PyTorch_Build\pytorch> Get-Process -Name git -ErrorAction SilentlyContinue | Stop-Process -Force (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 2. 清理目标目录 (rtx5070_env) PS E:\PyTorch_Build\pytorch> if (Test-Path $ClonePath) { >> Remove-Item -Path $ClonePath -Recurse -Force -ErrorAction Stop >> Write-Host "✅ 目录已清理: $ClonePath" -ForegroundColor Green >> } (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 3. 清理Git残留 (rtx5070_env) PS E:\PyTorch_Build\pytorch> $gitResidues = @( >> "$PWD\.git\index.lock", >> "$PWD\.git\shallow.lock", >> "$PWD\.git\modules", >> "$PWD\.gitmodules" >> ) (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> Get-Item -Path $gitResidues -ErrorAction SilentlyContinue | Remove-Item -Recurse -Force (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 4. 重置Git配置 (rtx5070_env) PS E:\PyTorch_Build\pytorch> git reset --hard HEAD 你看看清理好了吗?只清理刚刚克隆岛2.1.0 没清理别的吧?
最新发布
09-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值