티스토리 뷰

.gitignore 에서 미처 예외처리 하지 못하고, 데이터 성격의 무거운 파일을 github push 해버렸다. 뒤늦게 .gitignore 에 관련 폴더를 추가한 상태에서 로컬에 있는 파일은 나두고 싶고, gihub 의 파일만 삭제하는 과정.

 

아래 data 폴더 밑의 모든 파일이 현재 github 에 올라가 있는 상태.

원래 git rm 으로 실행하면 실제 로컬 폴더의 파일 삭제와 git index 에서도 삭제된다. 내가 원하는 옵션은 이게 아니고, 로컬 폴더는 건들지 않고, git index 에서만 해당 파일을 제거하여 git push 하는게 목적이므로, --cached 옵션을 사용한다. 그리고, 폴더내의 모든 파일을 제거 할 것이므로 , -r 도 추가.

> git rm --cached -r data/

 

실행하면, 해당 파일들이 실제 지워지지는 않았으나, git index 상에서만 제거되어, git status 를 확인하면 아래와 같이 삭제대상으로 나오게 됨. 

 

바로 git commit 처리하고, git push 처리까지 완료.

 

github 에서 해당 폴더가 제거 되었다. 

 

(참고) git rm Documentation (version 2.24.0)

Remove files from the index, or from the working tree and the index. git rm will not remove a file from just your working directory. (There is no option to remove a file only from the working tree and yet keep it in the index; use /bin/rm if you want to do that.) The files being removed have to be identical to the tip of the branch, and no updates to their contents can be staged in the index, though that default behavior can be overridden with the -f option. When --cached is given, the staged content has to match either the tip of the branch or the file on disk, allowing the file to be removed from just the index.

반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
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
글 보관함