Skip to content

How to recover after rejected large files commit

Issue: Trying push more than 10MB in one commit, then rejected from Gitlab

% ls docs/images
 3.1MB_video.mp4
 9.7MB_video.mp4

% git add .
% git commit -m "add 2 videos"
% git push
remote: fatal: pack exceeds maximum allowed size
error: remote unpack failed: unpack-objects abnormal exit
To gitlab.fabcloud.org:yuichitamiya/my-test-project.git
 ! [remote rejected] master -> master (unpacker error)
error: failed to push some refs to 'git@gitlab.fabcloud.org:yuichitamiya/my-test-project.git'

Recovery Step 1: Back the status before the last commit

Ref. 直前のコミット操作を取り消す

git reset --soft HEAD^

% git reset --soft HEAD^
// commit -m "add 2 videos"をする前(add .の後)の状態になった //backed to before "commit -m "add 2 videos"
% git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    new file:   docs/images/3.1MB_video.mp4
    new file:   docs/images/9.7MB_video.mp4

% ls docs/images
 3.1MB_video.mp4
 9.7MB_video.mp4

Recovery Step 2: Unadd the large file or folder from added files, then commit and push less than 10MB

Ref. ファイル/ディレクトリを指定して git add を取り消す

$ git reset file_name $ git reset /folder/

% git reset docs/images/9.7MB_video.mp4
// add から9.7MB_video.mp4を外した //unadd 9.7MB_video.mp4

% git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    new file:   docs/images/3.1MB_video.mp4

Untracked files:
  (use "git add <file>..." to include in what will be committed)
    docs/images/9.7MB_video.mp4

% ls docs/images
 3.1MB_video.mp4
 9.7MB_video.mp4

% git commit -m "add 3.1MB_video only"
% git push

Recovery Step 3: Add the unadded files, then commit and push

一旦addから外したファイルをaddする

% git status
On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
    docs/images/9.7MB_video.mp4

nothing added to commit but untracked files present (use "git add" to track)

% git add docs/images/9.7MB_video.mp4
// added agein the unadded 9.7MB_video.mp4
% git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    new file:   docs/images/9.7MB_video.mp4

% git commit -m "add 9.7MB_video only"
% git push


Last update: May 22, 2022