Skip to content

Stash: Keep Staged drops staged changes when stashing selected files #5369

Description

@ianhattendorf

Description

When stashing specific files (a file selection) and choosing Keep Staged, the staged changes are stashed away instead of being kept in the index.

This is the file-selection counterpart to #5281 — that issue's fix (c4d86fe, 18.1.0) only covered the no-selection Stash Unstaged Changes SCM group action (which passes no pathspecs).

Steps to Reproduce

  1. Make a staged change to a tracked file, plus a further unstaged change (or other unstaged files).
  2. In the Source Control view, select one or more tracked files (not all staged files).
  3. Stash the selection and choose Keep Staged.
  4. ❌ The staged change is stashed too — the index is reset instead of being kept intact.

Root Cause

stashPushCore adds --include-untracked to every pathspec push as a safety net (so a selected untracked file can be stashed). The --keep-index guard keyed off whether --include-untracked was present in the params, so it dropped --keep-index for every file-selection push — even tracked-only selections, where git's --keep-index --include-untracked -- <pathspec> bug doesn't apply.

Fix

Key the guard off the caller's actual intent (includeUntracked) instead. Tracked-only selections keep --keep-index and the index is preserved; selections that genuinely include untracked files still drop --keep-index to avoid the underlying git bug (where the restoring checkout can't match an untracked path in the index tree). That remaining untracked-in-selection case needs a fix in git itself and is tracked separately (see #5281).

GitLens Version

18.2.0 (present since 18.1.0)

Metadata

Metadata

Assignees

Labels

bugneeds-verificationRequest for verificationpending-releaseResolved but not yet released to the stable edition

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions