关于git:git-清理提交信息-commits-的常用方法

5次阅读

共计 631 个字符,预计需要花费 2 分钟才能阅读完成。

用 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 .git
git init
git add .
git cm "first commit"
git remote add origin [your_github_repo_url]
git push -f -u origin master

正文完
 0