git stash
git
Usage
git stash [push] [-u] [-m "<message>"]Parks your unfinished changes and gives you a clean tree; untracked files stay behind unless you pass -u, and pop removes the entry while apply keeps it.
Common flags
| Flag | Meaning |
|---|---|
| -u | include untracked files, which are otherwise left behind |
| -a | include ignored files too |
| -k | keep the staging area as it is |
| -p | stash selected hunks |
| pop | apply the newest entry and delete it |
| apply | apply it and keep the entry |
| list | show the entries |
| drop <stash> | delete one entry |
Examples
git stash -u -m "wip login"parks tracked and untracked changes under a name
git stash popbrings the newest stash back and removes it from the list
git stash apply stash@{2}applies an older entry and leaves it in the list
The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does git stash do?
Parks your unfinished changes and gives you a clean tree; untracked files stay behind unless you pass -u, and pop removes the entry while apply keeps it.
Q. How do I type it?
git stash [push] [-u] [-m "<message>"] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
8 are listed here; the full set is in man git. This command sits under git.
Related commands
man page: man git-stash