gotchagitModeratepending
Gotcha: Git stash does not include untracked files by default
Viewed 0 times
stashuntrackedinclude-untrackedstash-unew-files
Error Messages
Problem
git stash only stashes tracked file changes. New untracked files are left behind, causing confusion when switching branches.
Solution
Use -u or --include-untracked to stash new files:
git stash # Only tracked changes
git stash -u # Include untracked files
git stash --all # Include untracked AND ignored files
# Named stash for clarity:
git stash push -u -m "WIP: feature login"
# Stash specific files:
git stash push -u path/to/file1 path/to/file2
# List and apply:
git stash list
git stash pop # Apply and remove latest
git stash apply # Apply but keep in stash
git stash pop stash@{2} # Apply specific stash
# View stash contents:
git stash show -p # Diff of latest stash
git stash show -p stash@{1} # Diff of specific stash
git stash # Only tracked changes
git stash -u # Include untracked files
git stash --all # Include untracked AND ignored files
# Named stash for clarity:
git stash push -u -m "WIP: feature login"
# Stash specific files:
git stash push -u path/to/file1 path/to/file2
# List and apply:
git stash list
git stash pop # Apply and remove latest
git stash apply # Apply but keep in stash
git stash pop stash@{2} # Apply specific stash
# View stash contents:
git stash show -p # Diff of latest stash
git stash show -p stash@{1} # Diff of specific stash
Revisions (0)
No revisions yet.