2023. 2. 19. 13:42ㆍ나는 이렇게 학습한다/Git
문제 원인
깃허브 저장소에 DB 비밀번호 값을 올리는 대형 사고를 쳐버렸다.
별생각 없이 다시 로컬에서 해당 파일을 지우거나 수정 후 다시 commit 한 뒤
remote origin에 push 해도 히스토리상에 해당 정보가 남게 된다.
해결 방안
원본 레포지토리 클론(clone)
git clone --mirror [레포지토리 주소]
cd [레포지토리 폴더명]
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파일을 작업할 프로젝트의 로컬 최상위 경로에 저장
문제의 히스토리 파악
- 'database.py' 라는 파일 안에 password 값이 그대로 노출되어 있었기에 이 히스토리를 지워주어야 했다.
히스토리 삭제
- BFG Repo-Cleaner 을 이용해서 문제의 히스토리 삭제
java -jar [jar파일 경로] --delete-files [지울 파일 이름]
git reflog expire --expire=now --all && git gc --prune=now --aggressive
git push -f origin main
- 다음과 같이 뜨면 성공
- 깃허브 히스토리에서 문제의 히스토리 기록이 지워졌는지 확인
삭제 이후 깃이 꼬였을 때 해결 방법
- 혹시라도 원격 저장소와 로컬 저장소가 꼬였다면 다음 명령어 입력
- 단, local의 파일들은 모두 날라가도 문제없는 상황에서 "나는 그저 원격 git 저장소의 master를 내 local로 덮어 씌우고 싶다." 하는 상황에서만 사용!!!
git fetch --all
git reset --hard origin/master
git pull origin master
참고 자료
'나는 이렇게 학습한다 > Git' 카테고리의 다른 글
[Troubleshooting] git push -f 실패 (GH006) (0) | 2023.01.27 |
---|---|
[Troubleshooting] Github Actions 'npm ci' 실패 (0) | 2023.01.15 |