0

I have an error with too large file > 100MB and I cannot push

git push -u origin my_branch 

to Github. I have added this files/directories into .gitignore Then I have done:

git rm -r my_directories

And then

git commit -m "ignoring large files"

But I cannot push this changes to Github as in my history of commits between the last push and current push there are other commits that contains addition of this too large file. I have been committing locally with this files and pushes errors out.

So I need current state of code as in my last commit but without this intermediate history of commits.

I have tried such solution:

$ git log --oneline
$ git checkout master
$ git branch -f <branch_name> <commit_id>
$ git add <filename>
$ git commit --amend --no-edit

But here on git add I have noticed that git branch -f reverted my files on disk to state 2 weeks ago, and .gitignore changed to not ignoring too large files, and tried to add this files on disk. I have panic that this removed my 2 weeks of work, but fortunately executing with latest commit id reverted reversion. git branch -f

But now I am constantly in the place I have commit history with too large files that cannot be pushed on github.

How can I achieve this, and achieve this safely.

enter image description here

Michał Ziobro
  • 10,759
  • 11
  • 88
  • 143
  • The basic problem here is that there are still one or more commits in the history of the branch being pushed which contain the too large file. When you push, you are pushing that history as well. Possibly the best tool to use here would be Git's filter-branch. See this [canonical @torek answer](https://stackoverflow.com/questions/50968652/git-filter-branch-all-command) for a discussion about filter-branch. – Tim Biegeleisen Apr 02 '19 at 15:49
  • `filter-branch` indeed, or you can interactively rebase to remove the large file from the commit it is added (which will also remove the commit where you remove the large file). Which is the commit introducing the file you want to remove? – padawin Apr 02 '19 at 17:15
  • 1
    Possible duplicate of [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 Apr 02 '19 at 18:34
  • https://stackoverflow.com/search?q=%5Bgit%5D+remove+large+files+history – phd Apr 02 '19 at 18:34

0 Answers0