// 에드센스

어제 AWS 관련 인증 키들을 깃허브 리포지토리에 올려놓고 있었다는 사실을 알게 됐다. 깃허브에서 지우고 다시 커밋되지 않도록 .gitignore에 등록하였지만 리포지토리 히스토리상에는 이미 수 없이 남아있었다. 이를 해결하기위해 BFG Repo-Cleaner를 사용했다.


1. BFG Repo-Cleaner 설치

https://rtyley.github.io/bfg-repo-cleaner/

 

BFG Repo-Cleaner by rtyley

$ bfg --strip-blobs-bigger-than 100M --replace-text banned.txt repo.git an alternative to git-filter-branch The BFG is a simpler, faster alternative to git-filter-branch for cleansing bad data out of your Git repository history: Removing Crazy Big Files Re

rtyley.github.io

다운로드된 jar파일을 작업할 프로젝트의 로컬 최상위 경로에 저장했다.

 

 

 

2. 문제의 히스토리

이렇게 이미 삭제한 내용임에도 히스토리 상에서 공개가 되기에 이 부분을 제거해 주자.

 

 

git clone --mirror [리포지토리 주소]

java -jar [jar파일 경로] --delete-files [이 클래스에 연관된 커밋 히스토리를 제거]

git reflog expire --expire=now --all && git gc --prune=now --aggressive

git push -f origin main

 

 

 

나의 경우엔 다음과 같았다.

git clone --mirror https://github.com/llshl/fabinet.git

java -jar "C:\Users\lsh97\Desktop\IntelliJ WorkSpace\fabinet-gradle\bfg-1.14.0.jar" --delete-files AwsConfig.java

git reflog expire --expire=now --all && git gc --prune=now --aggressive

git push -f origin main

파일 경로상에 공백문자가 있을 경우 전체 경로를 ""로 감싸주면 된다.

 

 

 

이 결과 AwsConfig.java 파일에 관련된 히스토리는 삭제된다.

 

(사진은 AwsConfig가 아닌 다른 클래스긴 하지만 여기에도 인증코드가 있었고 잘 지워진 모습이다.)

 

 

 

 

참고:

'Git' 카테고리의 다른 글

[Git] Branch 이름 변경하기  (0) 2022.04.26
[Git] git stash  (0) 2021.11.24
[Git] Branch와 Merge  (0) 2021.08.14
[Git] git bash를 사용한 버전관리 시작하기  (0) 2021.08.13

+ Recent posts