Remove file '/public/js/build' from history

This commit is contained in:
gwokwong 2023-06-27 17:52:35 +08:00
parent d167efb52b
commit cfb8818f7b
2 changed files with 37 additions and 0 deletions

1
.gitignore vendored
View File

@ -26,3 +26,4 @@ laravels-timer-process.pid
vars.yaml
laravels.conf
laravels.pid
**//public/js//public/js/build

36
rewrite-history.sh Normal file
View File

@ -0,0 +1,36 @@
#!/bin/bash
# 用于删除历史纪录中指定文件的脚本
# 确认用户输入参数
if [ $# -ne 1 ]
then
echo "Usage: rewrite-history.sh <file-to-remove>"
exit 1
fi
# 获取文件名和目录路径
file_to_remove=$1
dir_path=$(dirname "${file_to_remove}")
# 移动到 Git 根目录
cd $(git rev-parse --show-toplevel)
# 移除指定文件
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch ${file_to_remove}" --prune-empty --tag-name-filter cat -- --all
# 删除备份文件
rm -Rf .git/refs/original/
# 清理垃圾文件
git reflog expire --expire=now --all && git gc --prune=now --aggressive
# 重置 Ignored 文件
echo "**/${dir_path}/${file_to_remove}" >> .gitignore
# 提交更改并强制推送到远程仓库
git add .
git commit -m "Remove file '${file_to_remove}' from history"
git push origin --force --all