Skip to content

Instantly share code, notes, and snippets.

@kekyo
Last active November 19, 2021 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kekyo/674b71cfc412ae01005273c104107763 to your computer and use it in GitHub Desktop.
Save kekyo/674b71cfc412ae01005273c104107763 to your computer and use it in GitHub Desktop.
Remove unused dirty nonsense files from Git repository with already committed.
#!/bin/sh
# 1. Put your adjusted genuine .gitignore file.
# 2.
git add .gitignore
git commit -m "Placed genuine .gitignore file."
# 3.
git clean -xfd
# 4.
git rm --cached `git ls-files --full-name -i -o --exclude-from=.gitignore`
#git ls-files -i -o --exclude-from=.gitignore | xargs git rm --cached
# 5.
git commit -m "Cleaners worked."
#!/bin/sh
# https://stackoverflow.com/questions/13541615/how-to-remove-files-that-are-listed-in-the-gitignore-but-still-on-the-repositor
# 1.
git rm -r --cached .
# 2. Put your adjusted genuine .gitignore file.
# 3.
git add .gitignore
git add .
# 4.
git commit -m "Cleaners worked."
#!/bin/sh
# https://stackoverflow.com/questions/13541615/how-to-remove-files-that-are-listed-in-the-gitignore-but-still-on-the-repositor
# 1. Put your adjusted genuine .gitignore file into /tmp.
git filter-branch --force --index-filter \
"git ls-files -i -X /tmp/.gitignore | xargs -r git rm --cached --ignore-unmatch -rf" \
--prune-empty --tag-name-filter cat -- --all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment