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?
If the large file was added in the most recent commit, you can just run: git rm --cached <filename> to remove the large file, then. git commit --amend -C HEAD to edit the commit.
Locally delete large files. Commit the local deletes. Soft reset back X number of commits (for me it was 3): git reset --soft HEAD~3 . Then recommit all the changes together (AKA squash) git commit -m "New message for the combined commit"
Github does support uploading and managing large files at once. Check out Git LFS. Using this you can manage/upload & control your project/repo having sizes larger than 100mb, noting that tha maximum repository size is less than equal to 10GB for free tier.
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:
$ git reset HEAD^
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)
$ git rebase -i 57d0b28
will drop you in an editor that resembles
pick 366eca1 This has a huge file pick d975b30 delete foo pick 121802a delete bar # Rebase 57d0b28..121802a onto 57d0b28 # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be aborted. #
Replace pick
with edit
on the line with the heavy commit
edit 366eca1 This has a huge file pick d975b30 delete foo pick 121802a delete bar
Save 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 --continue
From there, delete the offending file (--cached
removes the file from the index only)
$ git rm --cached big-nasty-file rm 'big-nasty-file'
amend the commit
$ git commit --amend
and finish the rebase
$ git rebase --continue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With