How to remove a too large file in a commit when my branch is ahead of master by 5 commits
A simple solution I used:
Do
git reset HEAD^
for as many commits you want to undo, it will keep your changes and your actual state of your files, just flushing the commits of them.Once the commits are undone, you can then think about how to re-commit your files in a better way, e.g.: removing/ignoring the huge files and then adding what you want and then committing again. Or use Git LFS to track those huge files.
When you deleted your file, that will be a change and that is the unstaged change that git is complaining about. If you do a git status you should see the file listed as removed/deleted. To undo this change you should git checkout -- <filename>
. Then the file will be back and your branch should be clean. You can also git reset --hard
this will bring your repo back to the status where you made your commit.
I am assuming that it is the last commit that has the very large file that you want to remove. You can do a git reset HEAD~
Then you can redo the commit (not adding the large file). Then you should be able to git push
without a problem.
Since the file is not in the last commit then you can do the final steps without a problem. You just need to get your changes either committed or removed.
http://git-scm.com/book/en/Git-Tools-Rewriting-History
The github solution is pretty neat. I did a few commits before pushing, so it's harder to undo. Githubs solution is : Removing the file added in an older commit
If the large file was added in an earlier commit, you will need to remove it from your repository history. The quickest way to do this is with The BFG (a faster, simpler alternative to git-filter-branch):
bfg --strip-blobs-bigger-than 50M
# Git history will be cleaned - files in your latest commit will *not* be touched
https://help.github.com/articles/working-with-large-files/
https://rtyley.github.io/bfg-repo-cleaner/