Created
July 7, 2024 19:45
-
-
Save jpsilvashy/76308aa9ac038973ddf40ff27720d06d to your computer and use it in GitHub Desktop.
Remove all the contents of your .gitignore file from the git history
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if .gitignore file exists | |
if [ ! -f .gitignore ]; then | |
echo ".gitignore file not found!" | |
exit 1 | |
fi | |
# Read each line in .gitignore | |
while IFS= read -r line | |
do | |
# Skip empty lines and comments | |
if [[ ! -z "$line" && ! "$line" =~ ^# ]]; then | |
# Remove leading slash if present | |
path="${line#/}" | |
echo "Removing path: $path" | |
git filter-repo --path "$path" --invert-paths | |
fi | |
done < .gitignore | |
# Force push the changes to the remote repository | |
git push --force --all | |
git push --force --tags | |
echo "Done removing paths listed in .gitignore" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment