clean-git

作者:Intopass
链接:https://www.zhihu.com/question/29769130/answer/45546231
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

一:常规办法
1.删除无用的分支

1
git branch -d <branch_name> 

2.删除无用的tag

1
git tag -d <tag_name>

3.清理本地版本库

1
git gc --prune=now

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

1.完全重建版本库

1
2
3
4
5
6
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.有选择性的合并历史提交

1
git rebase -i <first_commit>

会进入一个如下所示的文件

1
2
3
4
5
6
pick ba07c7d add bootstrap theme and format import
pick 7d905b8 add newline at file last line
pick 037313c fn up_first_char rename to caps
pick 34e647e add fn of && use for index.jsp
pick 0175f03 rename common include
pick 7f3f665 update group name && update config

将想合并的提交的pick改成s,如

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

这样第四个提交就会合并进入第三个提交。
等合并完提交之后再运行

1
2
git push -f
git gc --prune=now

文章标题:clean-git

本文作者:zhu8fei

发布时间:2018-01-11, 10:56:40

最后更新:2024-08-15, 09:38:35

原始链接:http://www.zhu8fei.com/2018/01/11/clean-git.html

版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。


转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 zhu8fei@163.com

目录
×

喜欢就点赞,疼爱就打赏