Last active
November 19, 2021 06:39
-
-
Save kekyo/674b71cfc412ae01005273c104107763 to your computer and use it in GitHub Desktop.
Remove unused dirty nonsense files from Git repository with already committed.
This file contains hidden or 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/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." |
This file contains hidden or 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/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." |
This file contains hidden or 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/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