Skip to content

How to recover after rejected large files commit

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
% 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

// 直前のコミット操作を取り消す
git reset --soft HEAD^

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
% 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

// ファイル/ディレクトリを指定して git add を取り消す
$ git reset file_name
$ git reset /folder/

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
% 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 less than 10MB

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
% 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