Git 本地和repo上仓库的清洗

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zjx923759789/article/details/83120279

思路

在于将庞大复杂的数据同步到本地,经过本地清洗后传回repo仓库。

实现步骤

注:本说明的所有命令都使用命令行运行(如:usr/bin/bash)
$,代表这是一个参数,需要更换为用户自己的具体对象

1.克隆仓库

git clone $url

2.执行清洗命令

cd到你克隆代码的根目录下
cd $your_clone_git_root

使用du -ha查看列表下有什么大文件,判断该文件是否需要

使用命令,将自己不需要的文件,或目录删除
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch $path-to-remove-file' --prune-empty --tag-name-filter cat -- --all
注意,其中的$path-to-remove-file是相对目录,相对于git仓库的根目录。
当看到# Ref 'refs/heads/ $branch' was rewritten,其中$branch是你的分支名。

3.推送修改后的repo

使用命令
git push $origin $master --force
$origin:本地remote中设置的别名
$master:希望覆盖的分支

4.清理和回收空间

使用命令
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now

5.检查.git目录是否缩小

参考资料

Git如何永久删除文件(包括历史记录)
https://www.cnblogs.com/cmsd/p/6880795.html
如何清洗 Git Repo 代码仓库
https://www.cnblogs.com/developer-ios/p/6211903.html

猜你喜欢

转载自blog.csdn.net/zjx923759789/article/details/83120279