Interview Prep/Git & GitHub/Lost Work, HEAD and History Problems

You added a file to `.gitignore`, but `git status` still shows it as modified.

BeginnerTroubleshootingLost Work, HEAD and History Problems
Answer

Likely causes → The file is already tracked. Ignore rules apply only to untracked files.

Diagnose →

git ls-files --error-unmatch path/to/file
git check-ignore -v path/to/file

Fix → git rm --cached path/to/file, commit, and the ignore rule takes over. For a whole folder, git rm -r --cached dir/.

Prevent → Write .gitignore before the first commit, using a template for your language.

All Git & GitHub questions Roadmap: Git & GitHub

More on Lost Work, HEAD and History Problems