-
Notifications
You must be signed in to change notification settings - Fork 39.1k
Git: Stash editor redirects to wrong stash when new stashes are created #290509
Description
Does this issue occur when all extensions are disabled?: Yes/No
- VS Code Version: N/A
- OS Version: N/A
Problem
View stash relies on stash index, but if a new stash is created while the last one is shown in editor, trying to open the now recent one with index 0 will not work, it will redirect to the already opened now stash 1.
How to Reproduce
- Make some changes in a repo then
git stashthem to create stash A (now atstash@{0}) - Open stash A using the Source Control stash menu → it opens a diff editor
- (Optional) Pin that editor tab (right-click tab → "Pin") - or just leave it open
- Make new changes and
git stashagain to create stash B (B is nowstash@{0}, A becomesstash@{1}) - Try to open the most recent stash B from the stash menu
- Bug: VS Code redirects to the already open editor (showing A, not B)
- Worse: Click "Pop Stash" or "Drop Stash" from that editor → operates on the wrong stash!
Solution
I've submitted a PR #288616 that fixes this by using the stash's commit hash (immutable) instead of index (shifts) as the editor identifier:
Side effect/Known limitation
When a stash editor is already open and the stash index shifts (due to new stashes being created), the editor title still shows the original index, even if you re-try to open the stash by View stash menu. The only way to get the updated index is by closing this editor and viewing the stash again.
Related Issues
I found this old issue #203188 that may be linked to this fix.