Skip to content

Instantly share code, notes, and snippets.

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 real666maverick/917e7e55ed07032a0965a12af1afbe67 to your computer and use it in GitHub Desktop.
Save real666maverick/917e7e55ed07032a0965a12af1afbe67 to your computer and use it in GitHub Desktop.
remove file or directory from git history
# Удаление файла из истории 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