您的位置:首页 > 其它

解决Git commit次数过多.git文件过大的问题

2017-07-11 00:00 399 查看
一:常规办法
1.删除无用的分支
$ git branch -d <branch_name>
2.删除无用的tag
$ git tag -d <tag_name>
3.清理本地版本库
$ git gc --prune=now

二:高级办法
注意高级办法会导致push冲突,需要强制提交,其他人pull也会遇到冲突,建议重新克隆。
!!!注意这些操作都很危险,建议找个示例库进行测试,确保自己完全掌握之后再实际操作。

1.完全重建版本库
$ 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

2.有选择性的合并历史提交
$ git rebase -i <first_commit>

会进入一个如下所示的文件
1 pick ba07c7d add bootstrap theme and format import
2 pick 7d905b8 add newline at file last line
3 pick 037313c fn up_first_char rename to caps
4 pick 34e647e add fn of && use for index.jsp
5 pick 0175f03 rename common include
6 pick 7f3f665 update group name && update config

将想合并的提交的pick改成s,如
1 pick ba07c7d add bootstrap theme and format import
2 pick 7d905b8 add newline at file last line
3 pick 037313c fn up_first_char rename to caps
4 s 34e647e add fn of && use for index.jsp
5 pick 0175f03 rename common include
6 pick 7f3f665 update group name && update config

这样第四个提交就会合并进入第三个提交。
等合并完提交之后再运行
$ git push -f
$ git gc --prune=now

ps:
只是为了 clone 小的话,用 --depth=1 只获取最新的 commit 即可
可以在 .gitignore 添加不需要的超大文件,然后重新建版本库
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: