![](/img/trans.png)
[英]Delete or remove all history, commits, and branches from a remote Git repo?
[英]git: Delete files and directories from all history but keep all branches (not just the master branch)
我試圖通過本教程從Git歷史記錄中刪除一些敏感文件和目錄。 但是,最后,我的新存儲庫只有一個分支:master分支。
在保留所有分支的同時,如何從Git歷史記錄中刪除文件和目錄?
謝謝!
我使用的命令(來自教程):
cd /tmp
git clone https://MY_GIT_REPOSITORY.git workingrepo
cd workingrepo
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master`; do
git branch --track ${branch##*/} $branch
done
git filter-branch --tag-name-filter cat --index-filter 'git rm -r --cached --ignore-unmatch FILE_LIST' --prune-empty -f -- --all
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --aggressive --prune=now
從您發布的內容來看,這應該有效。 該:
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master`; do git branch --track ${branch##*/} $branch done
序列應為原始存儲庫中的每個分支創建一個分支。 如果以后檢查分支集,則應該看到正確的名稱。 (與僅使用git clone --mirror
進行初始克隆相比,此方法有點笨拙,但有時有必要避免使用--mirror
來進行裸克隆。)
篩選器分支操作(在此處為發布目的而拆分的行):
git filter-branch --tag-name-filter cat \\ --index-filter 'git rm -r --cached --ignore-unmatch FILE_LIST' \\ --prune-empty -f -- --all
然后應在所有分支(操作--all
末); 索引過濾器將刪除一個名為FILE_LIST
的文件(假定這是實際文件列表的縮寫),您應該會看到許多進度消息以及filter-branch
更新的分支名稱列表。
此時,您可以再次檢查分支名稱。 它們的名稱應與以前相同(盡管它們指向的提交散列可能並且通常會有所不同)。
其余命令進行一些清理。 --aggressive
是不必要的(請參閱此處的Linus Torvalds的說明 ),但是使用git gc
或重新克隆對於丟棄不需要的對象是合適的。 這些將不會對分支名稱產生影響,因此這兩個特定點是檢查錯誤原因的地方。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.