Interview Prep/Git & GitHub/Undoing changes: reset, revert, restore and reflog

How do you stash only some files, or stash untracked and ignored files?

IntermediateConceptUndoing changes: reset, revert, restore and reflog
Answer

Use pathspecs, -u for untracked, -a for all including ignored, and -p to pick hunks. --keep-index stashes only unstaged changes.

git stash push -m "wip" -- src/api.py
git stash push -u
git stash push -p
All Git & GitHub questions Roadmap: Git & GitHub

More on Undoing changes: reset, revert, restore and reflog