Knows Not Much
Knows Not Much

Reputation: 31526

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
To https://github.dev.myc.com/p/p.git
 ! [remote rejected] feature/branch -> feature/branch (pre-receive hook declined)
error: failed to push some refs to 'https://github.dev.myc.com/p/p.git'

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
Password:
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.

Upvotes: 3

Views: 4981

Answers (3)

Vivek Kodira
Vivek Kodira

Reputation: 2914

I faced this issue and didn't want to revert back to an earlier version. The option I chose was to copy the repository elsewhere, clone it again and then overwrite the files with the original (except the large file).

Upvotes: 3

starlocke
starlocke

Reputation: 3661

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.

https://git-lfs.github.com/

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

https://git-scm.com/book/en/v2/Git-Tools-Submodules

Upvotes: 3

wrossmck
wrossmck

Reputation: 388

This is because your local git has a history of the large file. In git, the history contains the full file, even if it's been deleted in the latest version, this is so that you can undo a change. To get around this, you'll need to rewrite history, or revert the git repo to an earlier revision.

see the related link: How to revert Git repository to a previous commit?

Upvotes: 2

Related Questions