Created
May 7, 2018 09:40
-
-
Save real666maverick/917e7e55ed07032a0965a12af1afbe67 to your computer and use it in GitHub Desktop.
remove file or directory from 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
# Удаление файла из истории git | |
Бывает не продуманный .gitignore, бывает в git попадёт какой нибудь левый бэкапный файлик, бывает что файл с паролем уложился в репку! | |
Если в git добавлен файлик которого там быть не должно, делаем так: | |
`git filter-branch --force --index-filter 'git rm -rf --cached --ignore-unmatch FILE_TO_REMOVE_AND_PRUNE' --prune-empty --tag-name-filter cat -- --all` | |
Если файлик успел уехать в удаленную репу: | |
``` | |
git push origin --force --all | |
git push origin --force --tags | |
``` | |
Не забываем прибраться в локальном репосе: | |
``` | |
git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin | |
git reflog expire --expire=now --all | |
git gc --prune=now | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment