티스토리 뷰

* 요약
프로젝트를 commit 하는 과정에서 aws와 같은 정보가 담긴 application.properties가 포함한 것을 깨달음

문제점 1) : application.properties의 보안관련된 정보가 타인에가 노출됨
→ 해결방법 : .gitignore을 이용

문제점 2) : application.properties 삭제 후에도 github에 History가 남음
→ 해결방법 : git filter-brach를 이용해 해당 파일(application.properties)의 history 된 부분을 전체 삭제

 

 

1. application.properties파일을 .gitignore 이용해 commit 되지 않게 하기


1). gitignore 파일 만들기

- 프로젝트 root경로에. gitignore 파일 생성

 

2) 간단히 ignore 내용 입력하기

아래 사이트에서 간단히 문서를 만들 수 있음.

 

gitignore.io

Create useful .gitignore files for your project

www.toptal.com

 

 

 

- Ex. Intellij, Java 기입 후 생성하면 아래 사진처럼 명령어를 만들어 주는데 이를. gitignore 파일 안에 복사-붙여넣기하면 됨.

 

gitignore.io 사이트

 

예시 문서

 

3) 추가로 application.properties 추가하기

 

4) git 명령어 실행

git rm --cached {삭제할 캐시 파일 경로}
    Ex. git rm --cached src/main/resources/application.properties

git add .gitignore
git commit -m '커밋 내용 입력'

 

사진과 같이 ignore적용되면 색상이 변함


 

 

 

 

2.  Git filter-branch를 이용해 히스토리 삭제하기


1) git 명령어

▶ commit 개수 확인 명령어
git log --oneline | wc -l

▶ 'applcation-aws.properties'에 포함된 히스토리 삭제 명령어
git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch {해당 파일 경로}' --prune-empty -- --all

Ex.
git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch src/main/resources/application-aws.properties' --prune-empty -- --all

▶ git push 강제 명령어
git push origin main --force

 

 

 

terminal 결과 사진

 

※ 참고 블로그

 

Git - 특정 파일 히스토리 삭제 하기

보안상 리스크가 있는 파일을 Git 히스토리에 삭제하기 위해서는 filter-branch를 사용해서 삭제가 가능하다. git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch ' --prune-empty --tag-name-filter cat --

asecurity.dev

 

 

github 잘못 올라간 파일 히스토리까지 삭제하기

잘못해서 깃허브에 암호 파일이라던지, env 파일을 올려 난감한 상황에 처할 때가 있습니다. 저도 최근 .pem 파일을 push 해서 난처한 상황에 처하고 말았는데요. 이렇게 푸시까지 이루어진 상황에

donologue.tistory.com

 

 

※ git push orginal main --force 실행 시 참고사항


해당 명령어를 실행하면 username과 userpassword를 요구하는데 몇 번을 입력해도 문제가 되어 실행되지 않았음.

확인해 보니 토큰을 등록해야 했음.

 

 

아래 블로그를 참고했으니 참고!

 

[Mac] GitHub push token 오류 해결

Github 오류 7.29일 새벽 갑자기 git push가 안 되는 현상을 겪었다. 오류의 첫 줄이 무슨 말이냐면 Password 인증방식이 일시적으로 brownout(shutdown?)되었다. Password 대신에 personal access token을 사용해주세

hyeo-noo.tistory.com

 

 

결과적으로 아래와 같이 히스토리 삭제가 완료했음.

 

 

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함