MountainGo
[Git] 특정 파일 히스토리 삭제
gom20
2023. 1. 25. 19:48
public repository에 민감 정보가 포함된 파일 이력이 남아서,
강제로 해당 파일의 히스토리를 삭제할 필요가 있어서 찾아 보았다.
git local repository로 이동하여 cmd창을 열어 아래 명령어를 실행한다. (참고로 window os)
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch <파일 경로>" --prune-empty --tag-name-filter cat -- --all
예) src/main/resources/application.properties
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch src/main/resources/application.properties" --prune-empty --tag-name-filter cat -- --all
강제 push하여 히스토리 적용
git push origin main --force