clone - 初次拉取
git clone --depth 1 --single-branch --branch main --no-tags \
https://mirrors.tuna.tsinghua.edu.cn/git/llvm-project.git \
~/00CXX_GitRes/llvm-project
- –depth 1 只取最新一条提交
- –single-branch 不抓其它分支(LLVM 有几千个分支,不限制会多几百 MB)
- –no-tags 不抓 tag(LLVM 的 tag 极多,这是体积大头之一)
好习惯
克隆完立刻把“只更新 main、永不抓 tag、自动清理“固化进本地配置:
cd ~/00CXX_GitRes/llvm-project
## 良好习惯,后续每次拉取都要针对该本地仓库的基础配置进行优先设置
## bat .git/config ##进行查看该本地仓库的配置
git config --local remote.origin.fetch '+refs/heads/main:refs/remotes/origin/main'
git config --local remote.origin.tagOpt --no-tags
git config --local fetch.prune true
git config --local fetch.pruneTags true
git config --local gc.pruneExpire now常用别名
# 一条命令完成"取最新快照 + 丢弃本地提交/改动"
git config --local alias.update \
'!git fetch --depth 1 --no-tags --prune origin main && git reset --hard origin/main && git log --oneline -1'
# 定期瘦身
git config --local alias.slim \
'!git reflog expire --expire=now --all && git gc --prune=now --quiet && git count-objects -vH'注意:Git 没有持久化的“默认浅深度“配置项(fetch.depth 不是有效键,我查了本机 git 2.55 的配置文档确认过)。
所以 –depth 1 必须每次 fetch 时显式带上——这正是 git update 别名帮你固化的事,
别直接敲裸git pull。
后续更新:永远只有一份快照
cd ~/00CXX_GitRes/llvm-project
git update # = fetch --depth 1 + reset --hard,等价于下面两行验证“确实没在攒历史“
# 任何时候三条命令自检:
git rev-parse --is-shallow-repository # 必须是 true
git rev-list --count HEAD # 必须恒等于 1
git tag | wc -l # 必须恒等于 0
git count-objects -vH # size-pack 明显膨胀时跑一次 git slim如果 is-shallow-repository 变成 false,说明中间某次更新用了不带 –depth 的命令(或镜像不支持 shallow 而返回了全量),最省事的处理是删掉重克隆一次。
额外网络优化(可选):git config –global http.version HTTP/1.1 和 git config –global http.postBuffer 524288000 能缓解大包传输偶发卡死;如果你本机有代理(看到你装过 Geph),可以只给 GitHub 走代理、国内镜像直连
add - 添加到仓库
add .commit - 提交
git commit -m "Update File md"push - 推送
git push origin mianstatus - 状态
git status额外常见命令
cloc - 统计代码量
cloc . # 在当前目录下按文件类型进行代码量统计