Knows Not Much Knows Not Much - 1 year ago 125
Git Question

Git Large files detected

I performed some load testing by using JMeter and then tried to checkin my project into git

by doing

git add .
git commit -m "message"
git push

I got an error message

Counting objects: 13, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (13/13), done.
Writing objects: 100% (13/13), 50.13 MiB | 13.42 MiB/s, done.
Total 13 (delta 8), reused 0 (delta 0)
remote: error: GH001: Large files detected.
remote: error: File java_pid32554.hprof is 412.89 MB; this exceeds GitHub Enterprise's file size limit of 100.00 MB
! [remote rejected] feature/branch -> feature/branch (pre-receive hook declined)
error: failed to push some refs to ''

To resolve the error I did the following

git rm java_pid32554.hprof
rm java_pid32554.hprof
added */*.hprof to .gitignore

Now I can see that the offending file is deleted from local file system. To be sure I also did a search

MacBook-Pro:p (feature/branch>)$ sudo find / -name java_pid32554.hprof
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory
MacBook-Pro:p (feature/branch>)$

So the file is indeed gone.

Now when I try

git push

it again gives the same error message.... even though the file is deleted.

I will not mark this question as a duplicate of this

My question presents a direct error message from git and the answer below is much more clear and direct. The other thread is cluttered with different types of solutions.

Answer Source

This first approach assumes that you don't care about "tracking" the large file; and consequently don't care to keep a copy of it on GitHub. In that case, you'll need to "go back in time" to an earlier commit; to a commit before you added the large, offending file.

You can do the following to do that:

git tag too_big            # a "savepoint" just in case you care for it later
git log                    # find an earlier COMMIT_ID
git reset --hard COMMIT_ID # replace COMMIT_ID with the one found

# See how things are at this point
git status

If it's not clean after "git status", maybe you'd be interested in:

# Optionally, this will wipe things out
git clean -df

And then continuing your work from that point.

git push master     # assuming your branch is master

The tag will give you a point of reference if you ever need to restore that giant file. It will also cause problems when you try to push to GitHub, and thus, push only master as opposed to a general purpose (ambiguous) git push (possibly implying --all).

Alternatively, if you must apply "source code control" to the very large file for some reason, you can explore GitHub's LFS (Large File Storage) git extension.

It might be wise to have a git sub-repository (officially known as submodule) for handling large files.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download