dev-common

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

검은바람 2023. 8. 9. 13:34
반응형

 

 

git 특성상 소스파일이 아닌 용량이 큰 리소스 파일(동영상 같은)이 형상관리에 첨부되면 속도에 큰 영향을 줍니다.

다음 두가지 명령을 실행하면 모든 히스토리(스냅샷)에서 해당 파일을 삭제하게 됩니다.

$ git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch <path to file>' --prune-empty --tag-name-filter cat -- --all

$ git push origin master --force

 

Git Bash를 열고 해당 파일이 있는 디렉토리로 이동합니다.
다음 명령어를 실행합니다.
git filter-branch --index-filter 'git rm --cached --ignore-unmatch <filename>' --prune-empty --tag-name-filter cat -- --all

예를 들어, .gitignore 파일의 히스토리를 삭제하려면 다음과 같이 입력합니다.

git filter-branch --index-filter 'git rm --cached --ignore-unmatch .gitignore' --prune-empty --tag-name-filter cat -- --all

이 명령어는 .gitignore 파일을 삭제하고, 해당 파일에 대한 모든 히스토리를 재작성합니다.

주의 사항: 이 명령어는 Git의 히스토리를 변경하므로, 신중하게 사용해야 합니다. 히스토리를 잘못 변경하면 복구할 수 없을 수도 있습니다

반응형