특정파일 깃허브 전체 이력 삭제

2025. 9. 30. 20:53문제 해결 및 Tip

 

 

1. filter-repo 설치

brew install git-filter-repo

 

 

2. 삭제할 파일 선택 후 깃 이력에서 전체 삭제

   - 삭제할 파일 경로  : src/types/userInfo.ts

   - 로컬에서 파일 삭제 및 깃이력에서 해당 파일이 전체 삭제 된다.

git filter-repo --path src/types/userInfo.ts --invert-paths --force

 

 

로컬의 git 에서는 모든 커밋 이력에 src/types/userInfo.ts 경로의 파일이 삭제가 되지만,

저장소 히스토리를 파괴적으로 수정(rewrite) 하기 때문에,
실수로 원격에 잘못 푸시하는 걸 막기 위해 자동으로 origin을 삭제를 해서 아래 경고가 발생

 

remote repository 가 연결 해제 되기 때문에 다시 연결 필요

NOTICE: Removing 'origin' remote; see 'Why is my origin removed?'
        in the manual if you want to push back there.
        (was https://github.com/[유저명]/[레포지토리명].git)

 

 

3. reomte repository 에 다시 연결

git remote add origin https://github.com/[유저이름]/[레포지토리명].git

 

 

4. 깃허브에 전체 강제 푸시

git push origin --force --all