5

I am developing a Java AWT application with Intellij IDE. After I git committed my code, I push to the repository:

me@mine-laptop myproject (master)$ git push origin master
Enumerating objects: 77, done.
Counting objects: 100% (77/77), done.
Delta compression using up to 4 threads
Compressing objects: 100% (58/58), done.
Writing objects: 100% (76/76), 114.51 MiB | 957.00 KiB/s, done.
Total 76 (delta 5), reused 1 (delta 0)
remote: Resolving deltas: 100% (5/5), done.
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: 41b3b658daba463dbc5ad37bce34f785
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File java_pid66619.hprof is 661.61 MB; this exceeds GitHub's file size limit of 100.00 MB
To github.com:myname/myproject.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@github.com:myname/myproject.git'

It complains that I have a large file java_pid66619.hprof which fails the git push.

Then I added that file to my .gitignore and push again but still the same error.

Then I run command ls -la, I don't see that large file java_pid66619.hprof. I know that large file is heap dump.

My questions:

  1. Why I don't see that file with ls -al but git sill complains it when push?
  2. Why I git ignored it but git still complains it?
  3. How to get rid of this issue?
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Leem
  • 17,220
  • 36
  • 109
  • 159
  • 1
    1. Because it's in some previous not yet pushed commit but not in the working tree. 2. You cannot ignore tracked files; `.gitignore` only ignores untracked files. – phd Feb 14 '20 at 07:41
  • 2
    3. [How to remove/delete a large file from commit history in Git repository?](https://stackoverflow.com/questions/2100907/how-to-remove-delete-a-large-file-from-commit-history-in-git-repository) – phd Feb 14 '20 at 07:41
  • https://stackoverflow.com/search?q=%5Bgit%5D+remove+large+file+history – phd Feb 14 '20 at 07:42

1 Answers1

6

Try first

git rm --cached java_pid66619.hprof

At least, your .gitignore will be effective.

But if, after committing this deletion, the push still fails, that means the (huge) file was part of previous commits.
Even if you delete and ignore a file, if it was part of past commits being pushed, that would be enough to make said push operation fail for the same reason.

Try then

git filter-repo --path java_pid66619.hprof --invert-paths

And force push.

This uses the new newren/git-filter-repo, which replaces BFG and git filter-branch

My previous commit is the 1st commit of this repo which is just a README.md file

Then clone the repo again, copy your files in that new local cloned repository (minus, obviously, the huge one), add, commit and push.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 2
    I run `git rm --cached java_pid66619.hprof` but get error: `fatal: pathspec 'java_pid66619.hprof' did not match any files` – Leem Feb 14 '20 at 13:47
  • @Leem No problem. That means it is already deleted in HEAD, but probably still present in one of the commits you are trying to push. `git filter-repo` will get rid of it for you. Save your repository first, to be safe. – VonC Feb 14 '20 at 13:51
  • My previous commit is the 1st commit of this repo which is just a README.md file – Leem Feb 14 '20 at 13:55
  • I also tried `git filter-repo --path java_pid66619.hprof --invert-paths` But I get this: `git: 'filter-repo' is not a git command. See 'git --help'.` – Leem Feb 14 '20 at 13:56
  • @Leem Then the easiest way forward is to make a new local repo, copy your files in it, add; commit, put a remote origin to your GitHub repo, and force push. – VonC Feb 14 '20 at 13:57
  • 1
    @Leem Yes, you need to install it first: https://github.com/newren/git-filter-repo/blob/master/INSTALL.md – VonC Feb 14 '20 at 13:57
  • @Leem I have edited the answer with a practical solution. – VonC Feb 14 '20 at 13:58