티스토리 뷰

과오를 남기기 위한 글 .... 입니당

환경: Mac M1 Pro

 

1. GitHub에 실수로 대용량 파일 add, commit, push

GitHub에 생각 없이 170MB 용량의 csv를 add, commit 했더니 에러가 났어요..

GitHub의 최대 파일 용량 사이즈는 100MB라고 합니당..

remote: error: Trace: 8fb9a96bac0e851016ce8dded9398953b72ff904b39ba0af20e943024387f3ca
remote: error: See https://gh.io/lfs for more information.
remote: error: File 1_Data/case_fraud_prep.csv is 170.00 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
To https://github.com/yeoniiii/NLP-CaseLaw.git
 ! [remote rejected] main -> main (pre-receive hook declined)
error: 레퍼런스를 'https://github.com/yeoniiii/NLP-CaseLaw.git'에 푸시하는데 실패했습니다

그래서 뒤늦게 대용량 파일 add, commit에 대한 구글링을 움청 했는데요..

 

2. .gitignore 파일 만들기

VSCODE 이용해서 .gitignore 파일을 만들고 그 안에 '*.csv' 라는 텍스트를 입력 후 저장해줍니다.

그 다음 다시 git add . 를 시도 해주면 !!!! > 안됨..

 

3. log에서 csv 파일 지우기 시도

제가 이미 commit, push 시도까지 해버려서 log에 남고 아무리 'git rm -r cached *.csv' 명령어를 쳐도 안되는 겁니당.

(참고: https://stackoverflow.com/questions/33175721/how-do-i-get-git-to-ignore-my-csv-files)

 

4. 대용량 파일도 그냥 업로드 시도

어쩔 수 없이 대용량 파일도 안고 간다 !!! (참고: https://wooono.tistory.com/284)

  1. brew에서 git-lfs를 install 해주고 brew install git-lfs
  2. push 하고 싶은 상위 디렉토리로 이동해서 git lfs install
  3. Large File인 csv를 넣어줍니다. git lfs track "파일명"
  4. git add .gitattributes
  5. git add "파일명"
  6. git commit -m "커밋메세지"
  7. git push origin main

하지만 이것도 실패.. 로그를 되돌려야 함!!!!!!!

 

5. 로그 되돌리기 < 대참사

(참고: https://devdebin.tistory.com/177)

급기야.. git reset --hard 를 하고 마는ㄴ데..

이때 진짜 울고 싶었다,,,,,,,,

당시 내 상태

  • GitHub 레포지토리: 리드미 파일만 있는 깨끗한 상태
  • Local 디렉토리: 잘 정리된 코드 + 데이터 파일들 그득그득....

이었는데 병합을 잘못해버리는 바람에 Local 디렉토리 내의 코드와 파일들이 다 사라져버린 것이다.!!!! 🥹🥹

눈물 나는 나의 구굴링..

 

6. 로그 되돌리기

(참고: https://velog.io/@sonypark/reset-hard로-삭제한-커밋-git-reflog를-이용해-살리기)

결국 나를 살려준 건 reflog !!!!

 

7. 백업 브랜치 main으로 병합

backup으로 log를 살려준 뒤 backup 브랜치를 다시 main으로 병합했다.

git checkout backup
git branch main backup -f
git checkout main
git push origin main -f

 

8. 되살린 log에서 다시 대용량 파일을 업로드 하지 않은 log로 돌아가기...

(참고: https://eh0322.tistory.com/61)

돌고 돌아 다시 온... 로그 되돌리기....

  • 여기서 TIP !!!!!
    • git reset HEAD^
    • 를 사용하면 commit은 취소하고, 파일은 삭제하지 않고 보존할 수 있다....🥹
    • 이걸 알았다면 8번까지 안 왔을 텐데 !!

 

9. add .gitignore > add .

Git 할 때는 순서가 참 중요한 것 같다..

대용량 파일 업로드 전엔

  1. lfs로 .gitattributes를 부여하거나
  2. .gitignore에 대용량 파일명을 입력해두거나..

해야 한다.!!!!

 

10. GitHub 업로드 성공 !

GitHub 업로드 성공 ~!!

https://github.com/yeoniiii/NLP-CaseLaw

 

GitHub - yeoniiii/NLP-CaseLaw: CaseLaw NLP Analysis | 유사 판례 추천 시스템

CaseLaw NLP Analysis | 유사 판례 추천 시스템. Contribute to yeoniiii/NLP-CaseLaw development by creating an account on GitHub.

github.com

 

'Study > GitHub' 카테고리의 다른 글

[Git] 명령어 정리  (0) 2023.07.31
[GitHub] 왕초보!.. in Mac OS  (0) 2023.07.08
[GitHub] ReadMe & Markdown 정리  (0) 2023.03.04
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/06   »
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
글 보관함