![](/img/trans.png)
[英]Is it possible to move a bunch of files from one git repository to another while preserving (most) history?
[英]Permanentely remove files from a git repository while preserving the history
這是我的情況:
我有一個具有以下布局的git存儲庫
myrepo/
myrepo/index
myrepo/data/data01
myrepo/data/data02
myrepo/data/data03
...
我有數百個提交,每個提交都會更改索引文件並添加一個數據文件。 現在,存儲庫已經變得很大,我想徹底擺脫數據文件,不僅要從我的腦海中刪除它們,還要從元數據中刪除它們,從而減小存儲庫的實際規模。 但是我想這樣做,保留提交的其余部分(在添加數據的同時更改索引)。 那可能嗎?
我自己在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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.