I accidentally commited log/test.log but have never pushed it. I have since done a git rm to get rid of it. But when I try to push, I’m still getting a huge amount of data attempting to be transferred. Shouldn’t the git rm fix that problem. If not, how could I fix it?
I accidentally commited log/test.log but have never pushed it. I have since done a
Share
Don’t revert the commit and then push because the huge file will still be carried around in the history.
Given that you haven’t yet pushed it and that the commit you want to redo is the most recent, remove that commit from your history:
This will return your index to the state it was in on the parent commit (
HEAD^). Now you have a mulligan: add and commit the way you meant to the first time around.If you’ve made other subsequent commits, you’ll need to
git rebase -i <commit>where<commit>is the SHA-1 of the bad commit’s parent.For example (and note the SHA-1 will be different in your repo)
will drop you in an editor that resembles
Replace
pickwithediton the line with the heavy commitSave and quit your editor to return to your shell, where you’ll see a message of the form
Stopped at 366eca1... This has a huge file You can amend the commit now, with git commit --amend Once you are satisfied with your changes, run git rebase --continueFrom there, delete the offending file (
--cachedremoves the file from the index only)amend the commit
and finish the rebase