Git/强制覆盖:修订间差异
来自康健生活
| 第21行: | 第21行: | ||
== 新的强制覆盖的场景 == | == 新的强制覆盖的场景 == | ||
我现在使用腾讯的 CNB 做代码仓库,用来做数据库的备份...,试用一年之后,仓库大小涨到了5个GB。所以需要每年强制覆盖一次远程仓库,用来清除历史的 COMMIT。 | |||
{{shc|<syntaxhighlight lang="bash"> | |||
# 建立孤立分支 | |||
git checkout --orphan new_branch | |||
git add -A | |||
git commit -m "Initial commit: Clean repository history" | |||
git branch -D master | |||
# 重建主分支 | |||
git branch -m master | |||
git push -f origin master | |||
</syntaxhighlight>|$|/home/kwy}} | |||
我看其他人的网文教程,一般还推荐删除远程标签,但是我的场景里恰恰需要保留这些标签,所以此处仅仅留作参考 | |||
{{shc|<syntaxhighlight lang="bash"> | |||
# 查看所有远程标签 | |||
git ls-remote --tags origin | |||
# 获取所有远程标签名并逐个删除 | |||
git ls-remote --tags origin | awk '{print ":" $2}' | xargs git push origin | |||
</syntaxhighlight>|$|/home/kwy}} | |||