You committed a 500 MB video locally, not pushed yet. How do you remove it from the commit?
BeginnerScenarioUndoing Mistakes
Answer
Situation read → If it's in the last commit only, amend. If it's earlier, rewrite.
What I'd do →
- Last commit:
git rm --cached video.mp4 && git commit --amend --no-edit. - Earlier commit:
git rebase -i origin/main, mark the commitedit, remove the file,git commit --amend,git rebase --continue. - Add
*.mp4to.gitignoreor track via Git LFS. - Confirm:
git log --stat origin/main..HEAD.
Why → The blob is only in your local repo and gets collected after reflog expiry, so pushing never exposes it.
Interview tip → Run git count-objects -vH and git gc --prune=now if you want it gone immediately.
More on Undoing Mistakes
You committed on `main` when you meant to be on a feature branch. Nothing is pushed. Fix it.BeginnerYou made a typo in your last commit message and have not pushed.BeginnerA bad commit is already on shared `main`. Others have pulled it. How do you undo it?IntermediateYou ran `git reset --hard` and lost uncommitted-then-committed work. Can you get it back?IntermediateYou need to revert a merge commit on `main`. `git revert` says "commit is a merge but no -m option was given".IntermediateYou deleted a local branch with unmerged work by mistake.Beginner