请考虑以下情形:
我在自己的Git仓库中开发了一个小型实验项目A. 它现在已经成熟,我希望A成为更大的项目B的一部分,它有自己的大型存储库.我现在想添加A作为B的子目录.
如何将A合并到B中,而不会丢失任何一方的历史记录?
145M = .git/objects/pack /
我编写了一个脚本来添加每个提交和提交的差异大小,然后再从每个分支的尖端向后移动.我得到129MB,没有压缩,没有分支机构的相同文件和分支机构之间的共同历史记录.
Git考虑了所有这些因素,所以我期望更小的存储库.那么为什么.git这么大?
我弄完了:
git fsck --full
git gc --prune=today --aggressive
git repack
Run Code Online (Sandbox Code Playgroud)
要回答有多少文件/提交,我有19个分支,每个文件大约有40个文件.287次提交,发现使用:
git log --oneline --all|wc -l
Run Code Online (Sandbox Code Playgroud)
它不应该使用10兆字节来存储有关此信息.
手册页git filter branch说:
use "--tag-name-filter cat" to simply update the tags.
Run Code Online (Sandbox Code Playgroud)
后来甚至说:
use --tag-name-filter cat -- --all
Run Code Online (Sandbox Code Playgroud)
但是--all应该包括--tags,因此所有标签都应该被正确地重写.
一个小测试验证了这一点:
$ git init
$ mkdir dir
$ touch dir/file
$ git add .
$ git commit -am init
$ git ls-files
dir/file
$ git tag tag
$ git for-each-ref
3006eb0a031e40901122ac8984c85ad533982f8b commit refs/heads/master
3006eb0a031e40901122ac8984c85ad533982f8b commit refs/tags/tag
$ git filter-branch --subdirectory-filter dir -- --all
Rewrite 3006eb0a031e40901122ac8984c85ad533982f8b (1/1)
Ref 'refs/heads/master' was rewritten
Ref 'refs/tags/tag' was rewritten
$ git …Run Code Online (Sandbox Code Playgroud)