From 7b89cb187cdb617dcfe2b66b348dfba59ef7e25f Mon Sep 17 00:00:00 2001 From: sanj <67624670+iodrift@users.noreply.github.com> Date: Tue, 30 Jul 2024 20:55:02 -0700 Subject: [PATCH] Auto-update: Tue Jul 30 20:55:02 PDT 2024 --- gitpurge | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 gitpurge diff --git a/gitpurge b/gitpurge new file mode 100755 index 0000000..5831a9d --- /dev/null +++ b/gitpurge @@ -0,0 +1,33 @@ +#!/bin/bash + +# Ensure we're in a git repository +if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then + echo "Error: This script must be run inside a Git repository." + exit 1 +fi + +# Check if git-filter-repo is installed +if ! command -v git-filter-repo &> /dev/null; then + echo "Error: git-filter-repo is not installed. Please install it first." + echo "You can install it via pip: pip install git-filter-repo" + exit 1 +fi + +# Get a list of files that currently exist in the repository +current_files=$(git ls-files) + +# Create a file with the list of files to keep +echo "$current_files" > files_to_keep.txt + +# Use git-filter-repo to keep only the files that currently exist +git filter-repo --paths-from-file files_to_keep.txt --force + +# Remove the temporary file +rm files_to_keep.txt + +# Force push all branches +git push origin --all --force + +echo "Purge complete. All files not present in the local repo have been removed from all commits on all branches." +echo "The changes have been force-pushed to the remote repository." +