Skip to content

Git: Stash editor redirects to wrong stash when new stashes are created #290509

@ynss

Description

@ynss

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

  1. Make some changes in a repo then git stash them to create stash A (now at stash@{0})
  2. Open stash A using the Source Control stash menu → it opens a diff editor
  3. (Optional) Pin that editor tab (right-click tab → "Pin") - or just leave it open
  4. Make new changes and git stash again to create stash B (B is now stash@{0}, A becomes stash@{1})
  5. Try to open the most recent stash B from the stash menu
  6. Bug: VS Code redirects to the already open editor (showing A, not B)
  7. 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.

Metadata

Metadata

Assignees

Labels

bugIssue identified by VS Code Team member as probable buggitGIT issues

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions