Which changes go into stash?
By default, stash captures uncommitted changes, but not all types of files.
What is saved to stash by default
When you run:
bash
git stashThe stash captures:
- changes to tracked files in the working directory
- changes in the staging area
What is NOT captured by stash by default
- untracked files
- files ignored via
.gitignore
How to add untracked files
bash
git stash -uor
bash
git stash --include-untrackedIn this case, the stash captures:
- tracked files
- untracked files
How to add everything, including ignored files
bash
git stash -aor
bash
git stash --allSummary table
| Type of change | By default | -u | -a |
|---|---|---|---|
| Tracked files | yes | yes | yes |
| Staged changes | yes | yes | yes |
| Untracked files | no | yes | yes |
| Ignored files | no | no | yes |
Key phrasing for an interview
By default
git stashsaves the changes of tracked files from the working directory and staging area. Untracked and ignored files are not included unless the corresponding options are specified explicitly.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.