sh 从git存储库中永久删除文件/文件夹的脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 从git存储库中永久删除文件/文件夹的脚本相关的知识,希望对你有一定的参考价值。

#!/bin/bash
set -o errexit

# Author: David Underhill
# Script to permanently delete files/folders from your git repository.  To use 
# it, cd to your repository's root and then run the script with a list of paths
# you want to delete, e.g., git-delete-history path1 path2

if [ $# -eq 0 ]; then
    exit 0
fi

# make sure we're at the root of git repo
if [ ! -d .git ]; then
    echo "Error: must run this script from the root of a git repository"
    exit 1
fi

# remove all paths passed as arguments from the history of the repo
files=$@
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch $files" HEAD

# remove the temporary history git-filter-branch otherwise leaves behind for a long time
rm -rf .git/refs/original/ && git reflog expire --all &&  git gc --aggressive --prune

以上是关于sh 从git存储库中永久删除文件/文件夹的脚本的主要内容,如果未能解决你的问题,请参考以下文章

sh 从git存储库中删除所有标记(本地和远程)

如何从 git 存储库中删除文件而不实际删除文件 [重复]

从 Git 存储库中删除已从磁盘中删除的多个文件

从 Git 存储库中删除已从磁盘中删除的多个文件

如何从 git bash 屏幕中删除文件并从存储库中删除该文件? [复制]

如何从 Git 存储库中删除文件?