5

I added a 150MB video to my projects source files and, unawarely, committed it. I then tried to git push the commit to my remote repo and noticed the the push hung for a while and then eventually failed, spitting out this:

Counting objects: 17, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (16/16), done.
Writing objects: 100% (17/17), 145.48 MiB | 138.00 KiB/s, done.
Total 17 (delta 13), reused 0 (delta 0)
remote: Resolving deltas: 100% (13/13), completed with 12 local objects.
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: 8b4191f1a1055e7dea4412f80b5125d2
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File src/images/greystone_place.mp4 is 145.45 MB; this exceeds GitHub's file size limit of 100.00 MB

I tried adding the file to .gitignore but it was too late. Subsequent git push commands yielded the same result.

Next, I tried to reset HEAD --soft to the commit where I originally committed the large file (this was after a few more commits involving .gitignore). From there, I reset the file in question using git reset HEAD -- path/to/filename to the working directory and committed again. Doing this, I still ran into the same error.

I later realized that maybe using the --amend command would do the trick (based on this article), but this also didn't work.

I also tried using git rm --cached path/to/file while I was in a soft reset. This also failed.

I have begun reading about git rebase i and git filter-branch but they seem complicated and I'm not sure if I'm barking up the wrong tree with this approach.

I am not a Git expert but in a nutshell, I want to do a git push with my other changes and exclude this large file. Somehow, it seems to be intertwined in an earlier commit and is preventing me from making a push to my remote repo.

David Gaskin
  • 548
  • 7
  • 26

3 Answers3

2

As of the tutorial on GitHub about removing file from history, you can use the bfg tool or use git filter-branch as you mentioned in your question:

git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch PATH-TO-YOUR-FILE-WITH-SENSITIVE-DATA' --prune-empty --tag-name-filter cat -- --all

After that, you may need a force push (git push -f), since the history is modified.

I'm not sure if I'm barking up the wrong tree with this approach.

You may have an backup first :-) And GitHub may be another backup (since your push failed).

Geno Chen
  • 4,916
  • 6
  • 21
  • 39
0

You can do it easily via the following command,

git reset --hard origin/<branch_name>

You can also delete it locally with the hash.

git reset --hard <SHA-Code>

Hope it helps.

Kannaiyan
  • 12,554
  • 3
  • 44
  • 83
  • 1
    Will this command obliterate everything after the commit that I'm resetting to? I don't want to lose my other changes. – David Gaskin May 02 '19 at 18:14
0

Another simpler approach:

  • git clone your GitHub repository again, in a new separate folder
  • report your modifications there (without the huge file) (you could also cherry-pick past non-pushed commits from older repository)
  • add, commit and push.
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250