대용량 파일 commit 취소 & git LFS (Large File Storage)

Jomii·2023년 11월 14일
0

초보 git

목록 보기
2/2
post-thumbnail

commit 후 push했는데 파일 크기가 100MB가 넘어가서

다음과 같은 에러떴을 때

remote: error: File file4.ipynb is 150.45 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.

이미 푸시까지 해버린 상태에서 다시 돌아가기 위한 과정이다.



1. commit 이력 삭제

commit 이력은 삭제하고 코드 변경 내용은 남아있게 하고 싶다면 reset의 옵션으로 --mixed를 지정할 수 있다.

$ git reset --mixed {1번 commit hash}

해쉬값은 $ git log 또는 $ git reflog로 조회가 가능하다.

만약 commit reset을 시도하다가 git reset --hard로 지워진 커밋을 복구할 때도 $ git reflog를 사용하면 된다. (관련 링크)

위처럼 실행할 경우 커밋 이력은 날아가나 unStage 상태로 코드는 남아있다.


커밋 이력 안 날아가게 하고 싶다면 --soft로 지정할 수 있다.

$ git reset --soft HEAD^ // 마지막 1개의 commit을 취소
$ git reset --soft HEAD~2 // 마지막 2개의 commit을 취소

2. LFS 설치 및 file tracking

Git LFS는 대용량 파일 버전 관리를 위한 git 익스텐션으로, 별도의 lfs 서버에 파일을 올려놓고 git에서는 해당 파일을 찾을 수 있는 포인터를 가지도록 한다.

Install

  • Ubuntu에서 설치 (LFS는 Linux, Windows, Mac 모두 설치 가능하다.)

    $ curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
    $ sudo apt-get install git-lfs
  • Mac에서 설치

    // mac 환경에서 git-lfs 설치하기
    $ brew install git-lfs
  • Window에서 설치

    다음 링크에 접속해 다운

    Git Large File Storage


Usage

Git LFS를 사용하려는 레퍼지토리에서 다음의 커맨드를 실행해 lfs를 초기화한다.

$ git lfs install

LFS로 관리할 파일을 추가한다.

# git lfs track "파일 경로"
$ git lfs track "file.py"

LFS로 관리하는 파일 목록을 ls-files를 통해 확인할 수 있다.

$ git lfs ls-files

git lfs track을 하고 나면 .gitattributes 파일이 추가되는데, git lfs에 대한 설정이 .gitattributes 파일로 관리된다.

함께 add ., commit, push 해주면 100MB가 넘어가는 대용량 파일도 git에 저장할 수 있다.

$ git add .gitattributes
$ git commit -m "commit message"
$ git push origin main

profile
✉️ qtly_u@naver.com

0개의 댓글