git消除旧提交

时间:2015-08-09 16:53:54

标签: git github

我在github(gh-pages)上托管了这个网站:http://ktsaou.github.io/blocklist-ipsets/。它是一个有2个brances的repo:master(存储源文件的地方)和gh-pages(主要是站点的json文件)。数百个文件每隔几分钟自动更新一次,每天约200次提交到两个分支机构。当然,每个提交都会更新文件,而且永远不会更新文件。

问题是回购正蓬勃发展。在短短几天内,每个分支在磁盘上占用大约1GB。现在我每天运行git gc --aggressive --prune=now以最小化它们的大小,当它们达到1GB时,我清理所有内容并从零开始。

我已经尝试过所有缩小回购的方法,但没有运气。

检查此示例:

#!/bin/bash
cd /tmp/test1 || exit 1
[ -d .git ] && rm -rf .git

git init
touch file.txt
git add file.txt

for x in {1..20}
do
        # create a new file
        echo "commit $x" >file.txt

        # copy a big file, but make some changes to it
        cat /var/log/messages | sort -R >>file.txt

        # commit it
        git commit file.txt -m "commit $x"

        if [ $x -eq 1 ]
        then
                echo
                echo "Size after $x commits:"
                du -s -h .git

                git gc --aggressive --prune="now"

                echo
                echo "Size after $x commits and aggressive garbage collection:"
                du -s -h .git
        fi
done

#git log | cat

echo
echo "Size after $x commits:"
du -s -h .git

git gc --aggressive --prune="now"

echo
echo "Size after $x commits and aggressive garbage collection:"
du -s -h .git

git log | grep ^commit | head -n 1 | cut -d ' ' -f 2 >.git/info/grafts

git filter-branch -- --all

echo
echo "Size after $x commits and graft:"
du -s -h .git

git gc --aggressive --prune="now"

echo
echo "Size after $x commits, graft and aggressive garbage collection:"
du -s -h .git

这是输出:

# bash test.sh
Initialized empty Git repository in /tmp/test1/.git/
[master (root-commit) e63c3a5] commit 1
 1 file changed, 11926 insertions(+)
 create mode 100644 file.txt

Size after 1 commits:
560K    .git
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), done.
Total 3 (delta 0), reused 0 (delta 0)

Size after 1 commits and aggressive garbage collection:
252K    .git
[master b054c76] commit 2
 1 file changed, 11825 insertions(+), 11825 deletions(-)
[master ba5eae5] commit 3
 1 file changed, 11774 insertions(+), 11774 deletions(-)
[master ad5842f] commit 4
 1 file changed, 11795 insertions(+), 11795 deletions(-)
[master 8edcf5f] commit 5
 1 file changed, 11797 insertions(+), 11797 deletions(-)
[master 09fefb6] commit 6
 1 file changed, 11793 insertions(+), 11793 deletions(-)
[master 26a89b9] commit 7
 1 file changed, 11791 insertions(+), 11791 deletions(-)
[master a5569ae] commit 8
 1 file changed, 11810 insertions(+), 11810 deletions(-)
[master 9120440] commit 9
 1 file changed, 11785 insertions(+), 11785 deletions(-)
[master b6c17ed] commit 10
 1 file changed, 11815 insertions(+), 11815 deletions(-)
[master 493ea14] commit 11
 1 file changed, 11838 insertions(+), 11838 deletions(-)
[master f41e066] commit 12
 1 file changed, 11832 insertions(+), 11832 deletions(-)
[master 9cb0c1a] commit 13
 1 file changed, 11803 insertions(+), 11803 deletions(-)
[master 8160cf1] commit 14
 1 file changed, 11803 insertions(+), 11803 deletions(-)
[master c7563a8] commit 15
 1 file changed, 11796 insertions(+), 11796 deletions(-)
[master e57c5e1] commit 16
 1 file changed, 11824 insertions(+), 11824 deletions(-)
[master 4a55c03] commit 17
 1 file changed, 11807 insertions(+), 11805 deletions(-)
[master a23ad81] commit 18
 1 file changed, 11791 insertions(+), 11791 deletions(-)
[master f504fe8] commit 19
 1 file changed, 11817 insertions(+), 11817 deletions(-)
[master 3f10dde] commit 20
 1 file changed, 11783 insertions(+), 11783 deletions(-)

Size after 20 commits:
4,9M    .git
Counting objects: 60, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (40/40), done.
Writing objects: 100% (60/60), done.
Total 60 (delta 19), reused 2 (delta 0)

Size after 20 commits and aggressive garbage collection:
1,9M    .git
Rewrite 3f10ddeca786824d43988becd99990ab039b34d3 (1/1)
Ref 'refs/heads/master' was rewritten

Size after 20 commits and graft:
1,9M    .git
Counting objects: 61, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (41/41), done.
Writing objects: 100% (61/61), done.
Total 61 (delta 20), reused 41 (delta 0)

Size after 20 commits, graft and aggressive garbage collection:
1,9M    .git

如您所见,嫁接并未解决问题。 制作后的回购尺寸与嫁接前的尺寸完全相同。

如何缩小回购的想法?

0 个答案:

没有答案