From cfb8818f7b8444db39167a161781cb2b29704e66 Mon Sep 17 00:00:00 2001 From: gwokwong Date: Tue, 27 Jun 2023 17:52:35 +0800 Subject: [PATCH] Remove file '/public/js/build' from history --- .gitignore | 1 + rewrite-history.sh | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 rewrite-history.sh diff --git a/.gitignore b/.gitignore index eb3f4b4a4..b180b3f37 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ laravels-timer-process.pid vars.yaml laravels.conf laravels.pid +**//public/js//public/js/build diff --git a/rewrite-history.sh b/rewrite-history.sh new file mode 100644 index 000000000..c7dbd1dbd --- /dev/null +++ b/rewrite-history.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# 用于删除历史纪录中指定文件的脚本 + +# 确认用户输入参数 +if [ $# -ne 1 ] +then + echo "Usage: rewrite-history.sh " + 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 + +