【问题标题】:Permanentely remove files from a git repository while preserving the history从 git 存储库中永久删除文件,同时保留历史记录
【发布时间】:2013-03-24 19:53:46
【问题描述】:

这是我的情况:

我有一个具有以下布局的 git 存储库

myrepo/
myrepo/index
myrepo/data/data01
myrepo/data/data02
myrepo/data/data03
...

我有几百个提交,每个提交都会更改索引文件并添加一个数据文件。现在,存储库变得非常大,我想完全摆脱数据文件,不仅将它们从我的脑海中删除,还从元数据中删除,从而减少存储库的实际大小。但我想这样做,保留我提交的剩余部分(在添加数据的同时完成索引的更改)。这可能吗?

【问题讨论】:

    标签: git revision-history


    【解决方案1】:

    我自己在github 上找到了答案。以下是必要的命令:

    git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch data/*' --prune-empty --tag-name-filter cat -- --all
    rm -rf .git/refs/original/
    git reflog expire --expire=now --all
    git gc --prune=now
    git gc --aggressive --prune=now
    

    【讨论】:

      猜你喜欢
      • 2019-03-17
      • 2013-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多