본문 바로가기

백앤드 개발/git

[GIT] GitHub 저장소 특정 파일의 커밋 기록 제거

1. 문제

.gitignore 가 반영이 되지 않은 채로 민감정보가 포함된 application-db.properties 가 push 됐다.

커밋 기록은 그대로 두고 application-db.properties 의 커밋 기록만을 제거하고 싶었다.

민감정보  application-db.properties가 포함된 커밋 기록

2. 해결방법

다음과 같이 Git 에 내장된 filter-branch 로 데이터를 삭제할 수 있다.

# 불필요한 파일과 커밋 제거
$ git filter-branch -f --index-filter "git rm --cached --ignore-unmatch [파일경로/파일명]" --prune-empty -- --all

# 원격 저장소 push
$ git push --force --all

 

경로가 포함된 예시

$ git filter-branch -f --index-filter "git rm --cached --ignore-unmatch ./lolcommunity/src/main/resources/application-db.properties" --prune-empty -- --all
$ git push --force --all

 

아래와 같은 메시지가 뜬다면 정상적으로 삭제된 것

 

아래와 같이 민감정보 application-db.properties 가 사라진 커밋기록을 확인할 수 있다.

민감정보가 제거된 커밋기록

 

3. 참조

https://cobi-98.tistory.com/48

 

[Git] GitHub 저장소의 특정 파일, 디렉토리 커밋기록을 모두 제거하기

GitHub GitHub는 로컬저장소를 이용한 빠른 퍼포먼스와 브랜치를 통한 효율적인 협업을 이룰 수 있으며, 등록 사용자와 비등록 사용자 모두에게 사이트의 공개 저장소를 찾아볼 수 있는 권한을 제

cobi-98.tistory.com

 

'백앤드 개발 > git' 카테고리의 다른 글