반응형
작업이 완료되고 커밋을 하기 위해서 git status를 확인해 봤다. 분명 gitignore에 추가한 파일인데 목록에 보이는 것이었다.
처음에는 gitignore 파일 설정을 잘못한 것인지, 파일 명에서 오타가 난것인지 확인하였지만 찾을 수 없었고 어쩔 수 없이 수동으로 그 파일을 무시한 채 커밋을 진행하였다.
시간이 지나고 알게된 것은 Cache(캐시)가 남아 있어서 발생하는 에러였다.
이미 커밋을하고나서 커밋하면 안 되는 파일이라는 것을 알게 되고 부랴 부랴 gitignore에 추가하였는데, 이미 저장소에 푸시된 파일이어서 git에서 그 파일을 추적하고 있는 것이었다.
이것을 해결하기 위해서 추적하지 않아야 하는 파일을 gitignore에 넣고 인덱스 파일을 지우는 과정을 진행하였다.
gitignore 파일 수정
추적하지 않아야 하는 파일을 '.gitignore'파일에 추가한다.
예시로 .env 파일이라고 가정하고 진행한다.
GIt 인덱스에서 파일 제거
이미 추적되고 있는 파일을 GIt의 인덱스에서 제거해야 한다. 'git rm --cached'명령어를 통해서 지울 수 있는데, 다른 블로그를 보면 전체 캐시를 다 지우고 진행하는데 아래처럼 파일명을 옵션으로 줌으로써 특정 파일에 대한 인덱스만 제거할 수 있다.
git rm --cached .env
변경사항 커밋 & 푸시
이제 변경사항을 커밋하여 인덱스에서 파일을 제거한 내용을 저장소에 반영해 주면 된다.
git commit -m "Remove .env from index and update .gitignore"
git push origin main
아래는 내가 진행한 커밋 내용이고, 아래처럼 커밋이 된다면 성공한 것이다.
반응형
'GIT' 카테고리의 다른 글
[GIT] 깃허브 자격 인증 데이터 변경 시, access token 재 등록하기 (0) | 2024.08.08 |
---|---|
[git] git repository 합치기 - commit 기록 남기기 (0) | 2024.07.18 |
[GIT] Pre-commit 사용법 및 설정 가이드 (0) | 2024.05.17 |
[Github] Git에서 푸시한 커밋 메시지 수정 방법 (0) | 2024.05.16 |
[GitHub] GitHub에서 여러 리포지토리의 이슈/PR 템플릿과 라벨 복사 방법 (0) | 2024.05.14 |