用 git 管理文件的时候,commit 多了可能发现 .git 目录十分大,甚至远超治理的文件自身。上面是一些减小 .git 文件大小的办法。
清理优化本地版本库
git gc --prune=now
清理合并不必要的commit
利用 rebase 变基,交互式抉择和合并commit
git rebase -i [commit_id]
齐全革除提交信息/重建版本库
!!留神提前备份数据,且不要在公共分支上这么做
基本思路1:创立一个新的 orphan 分支,代替原来的分支
应用 --orphan 命令创立新的分支时,这个新建的分支和其余分支不会有任何关系,它不会蕴含任何先前的提交记录或者历史记录。相当于新建了一个洁净的空分支,并让该分支指向一个全新的根节点。不过这个办法只能让近程的commit清空,本地原有的 .git 还是会比拟大。
git checkout --orphan <new-branch-name>git add .git commit -am "Initial commit"git branch -D <old-branch-name>git branch -m <old-branch-name>git push -f origin <old-branch-name>
基本思路2:间接删除 .git 而后从新初始化 git
rm -rf .gitgit initgit add .git cm "first commit"git remote add origin [your_github_repo_url]git push -f -u origin master