Video in progress
What does `git stash` actually save, and in which cases do your changes not end up in the stash?
A stash is made of special commits: one for the index state, one for the working tree, and a third one for untracked files if requested. By default untracked and ignored files do not go into the stash, and you need -u or -a for them.
📖 Answer
git stash push -m "kesh tajribasi" # tracked changes
git stash push -u -m "yangi fayllar ham" # + untracked
git stash list
git stash show -p stash@{1}
Inside there is refs/stash, which points to an object resembling a merge commit. So even if you accidentally run git stash drop, you can find it for quite a while through git fsck --unreachable | grep commit.
The usual surprises:
- a newly created
PaymentRetryPolicy.javastays on disk even after the stash, because it was untracked; - if
git stash popends with a conflict, the stash is not deleted. After you resolve the conflict, you rungit stash dropby hand; popdoes not restore the index state by default: everything comes back unstaged. If you need it,git stash pop --index.
A stash is not a good place for long-term work: the names are quickly forgotten, and which branch it came from gets confusing. If it sits for more than a day, I turn it into a branch with git stash branch wip/kesh stash@{0}.
Sign up to mark studied questions and save your progress.