Let’s say I was doing stuff in a local directory. I added a large file, I commit and push, but I get an error stating that the file is too large. If I didn’t care about this file making its way to the Github repo, how can I go about removing it from the commit without ruining the rest of my progress? I tried deleting the file, re-adding and re-commiting, but I get the same error when I push. So far my workaround has been to copy everything in the directory except .git to a different, temporary folder, revert to origin/master, and then replace everything back in with the changes I want. I haven’t found a good solution for just… ignoring the large file or removing it from the commit, nothing I’ve found online has worked and the commit always just fails because of the large file.
If you have additional commits made after the commit that added the big file, you can use interactive rebase to edit the offending commit and redo the rest on top of it. If the offending commit is the latest one, then you can use reset --soft
VibeSurgeon@piefed.social 4 hours ago
If it’s the last commit, you can undo the commit, and re-make it as you please by using
git reset HEAD~1. You can then stage the files you actually want in the commit.Another option is to amend the commit to not include that file, by doing
git rm --cached <filename>followed bygit commit --amend.The reason you can’t do the prior in a separate follow-up commit is that the file would still be in the git history, and hence it must be pushed to GitHub along with the rest of the repo files.
If the problem is not on the latest commit, you can do an interactive rebase, and re-do the commit that way.