Interview Prep/Git & GitHub/Undoing Mistakes

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 →

  1. Last commit: git rm --cached video.mp4 && git commit --amend --no-edit.
  2. Earlier commit: git rebase -i origin/main, mark the commit edit, remove the file, git commit --amend, git rebase --continue.
  3. Add *.mp4 to .gitignore or track via Git LFS.
  4. 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.

All Git & GitHub questions Roadmap: Git & GitHub

More on Undoing Mistakes