Here's how to undo your last commit (that accidentally included __pycache__
) and prevent it from being tracked in the future:
git reset --soft HEAD~1
- This will:
- Remove the commit (
fd8b15c
) - Keep all your changes staged
- Allow you to re-commit without
__pycache__
- Remove the commit (
git restore --staged */__pycache__/*
or for all Python cache files:
git restore --staged *.pyc __pycache__/
git commit -m "python crash course" # Now without __pycache__
echo "__pycache__/" >> .gitignore
echo "*.pyc" >> .gitignore
Then commit the .gitignore
:
git add .gitignore
git commit -m "Add .gitignore for Python cache"
If you want to erase the commit and all changes:
git reset --hard HEAD~1
(Warning: This permanently deletes uncommitted work!)
git restore --staged .
unstaged all files, but didn't undo the commit.- The files remained in Git's history until you ran
reset
.
--soft reset
→ Best for fixing bad commits..gitignore
→ Essential for Python projects.- Always check
git status
before committing!
Let me know if you'd like help with anything else! 😊