Skip to content

Conversation

@ynss
Copy link

@ynss ynss commented Jan 17, 2026

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.

I found this bug when I pinned a stash A diff editor, then worked on something else and created a new stash B. When I tried to open the recent stash B, VS Code redirected me to the pinned editor showing the OLD stash A instead. This was very confusing - I thought my recent stash wasn't saved correctly or was lost, and almost started redoing the changes A from scratch, but I saw with git stash list that it was there but now with index {1}...

This is not only pinned stash - it can be simple opened and kept stash diff.

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

With unique hash per stash, every opened editor is linked to its exact stash diff, and trying to open any new stash will open a new tab.

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.

Testing

I manually tested with the reproduction steps above. After the fix:

  • Opening stash B opens a new tab (no redirect)
  • Pinned stash editors remain linked to the correct stashes.

Related Issues

I found this old issue #203188 that may be linked to this fix.

Copilot AI review requested due to automatic review settings January 17, 2026 14:55
@vs-code-engineering
Copy link

vs-code-engineering bot commented Jan 17, 2026

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@lszomoru

Matched files:

  • extensions/git/src/artifactProvider.ts
  • extensions/git/src/commands.ts

@ynss
Copy link
Author

ynss commented Jan 17, 2026

@microsoft-github-policy-service agree

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes a bug where stash diff editors would incorrectly redirect when stash indices change. The fix replaces index-based stash identification with hash-based identification using the stash commit hash.

Changes:

  • Changed stash artifact IDs from stash@{index} format to commit hash for stable identification
  • Updated stash URI generation to use hash instead of index
  • Refactored stash lookup methods to find stashes by hash rather than index

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
extensions/git/src/artifactProvider.ts Changes stash artifact ID from stash@{index} to the commit hash for stable identification
extensions/git/src/commands.ts Updates stash identification logic throughout: getStashFromUri now validates and matches by hash, _viewStash uses hash in URIs, adds _findStashByArtifactId helper, and updates all artifact stash commands to look up by hash

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.

This results in random behavior and seems like if the recent
stash wasn't saved correctly or lost.

With unique hash per stash, every opened editor is linked to
its exact stash diff, and trying to open any new stash will
open a new tab.
@ynss ynss force-pushed the git/use-stash-hash-for-editor-identity branch from 0944b36 to ee8d123 Compare January 17, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants