写一个脚本使用 git 强制更新到最新版本 和 过滤掉指定的多个文件和文件夹
#!/bin/bash
指定需要过滤的文件和文件夹
FILTERS=("file1" "folder1" "folder2")
切换到项目目录
cd /path/to/project
强制更新到最新版本
git fetch --all git reset --hard origin/master
过滤指定的文件和文件夹
for FILTER in "${FILTERS[@]}" do git filter-branch --force --index-filter "git rm --cached --ignore-unmatch $FILTER" --prune-empty --tag-name-filter cat -- --all done
清理无用的 git 数据
rm -rf .git/refs/original/ git reflog expire --expire=now --all git gc --prune=now
echo "更新成功!"
原文地址: https://www.cveoy.top/t/topic/dh65 著作权归作者所有。请勿转载和采集!