Skip to content

Keep multiple stashes and stash checked files - #23275

Open
devcustrom wants to merge 1 commit into
desktop:developmentfrom
devcustrom:pr/upstream-stashes
Open

devcustrom wants to merge 1 commit into
desktop:developmentfrom
devcustrom:pr/upstream-stashes

Conversation

@devcustrom

Copy link
Copy Markdown

Closes #12699, closes #11531

Description

GitHub Desktop currently keeps only the newest stash entry per branch: git-store deliberately drops every older Desktop-created stash, and createStashAndDropPreviousEntry deletes the previous stash whenever the user stashes all changes or switches branches with "stash on current branch".

This PR keeps the full stash stack for the current branch and surfaces it in the Changes sidebar:

  • Every Desktop-created stash for the current branch is listed, newest first, with its creation time. Selecting a row opens the existing stash diff view; Restore/Discard act on that specific entry (identified by SHA, so reflog index shifts don't matter).
  • Stashing no longer overwrites the previous entry, so the overwrite confirmation dialog and its menu labels are removed. Renaming a branch moves all of its stash entries, preserving order and timestamps.
  • A new "Stash Checked Changes" context-menu action stashes only the files whose include-in-commit checkbox is checked, using literal pathspecs with git stash push -- .... Unchecked changes remain in the working directory, and selected untracked files are staged first as before.

The list is still limited to Desktop-created stashes (the existing !!GitHub_Desktop<branch> marker) for the checked-out branch; command-line stashes remain hidden, as before.

Note: #12699 and #11531 are currently labeled not-planned. This PR is a working implementation in case the team revisits that decision; the underlying issues describe the same user-facing problems.

Testing performed:

  • npx tsc -p tsconfig.json --noEmit
  • New unit tests for multiple entries per branch, creation timestamps, and partial stashing via pathspec; existing stash tests pass.
  • Manual: three stashes listed independently, restore/discard individually, partial stash leaves unchecked files untouched.
  • Production build and Windows installer built successfully.

Screenshots

Screenshots are not included in this environment; the UI change is a list of existing stash rows in the Changes sidebar, reusing the existing stash diff viewer.

Release notes

Notes: Add support for keeping multiple stashes per branch and stashing only checked files.

Keep every Desktop stash entry for a branch instead of only the newest
one, and show them as a list in the Changes sidebar. Each entry can be
selected, viewed, restored, or discarded by its SHA.

Stashing no longer overwrites the previous stash entry, so the overwrite
confirmation dialogs and labels are gone. Branch renames move all stash
entries for the branch.

Also add a Stash Checked Changes action to the changes context menus
which passes the checked files as literal pathspecs to git stash push.
@devcustrom
devcustrom requested a review from a team as a code owner December 3, 2026 09:08
@devcustrom
devcustrom requested review from sergiou87 and a balanced review from Copilot December 3, 2026 09:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Restricted stashing can include unchecked staged files and leave checked rename deletions behind, while stash failures go unreported and leave the dialog stuck loading.

4 open issues
What changed in this PR

Extends GitHub Desktop’s branch-specific stashing to retain multiple entries and stash checked files, addressing the workflows described in #12699 and #11531.

Changes:

  • Lists timestamped stashes and tracks selection by SHA.
  • Adds checked-file stashing using literal pathspecs.
  • Removes overwrite confirmations and preserves stashes during branch renaming.
File Description
app/​test/​unit/​ui/​stash-and-switch-branch-dialog-test.tsx Updates dialog props.
app/​test/​unit/​main-process/​menu-test.ts Removes obsolete confirmation flag.
app/​test/​unit/​git/​stash-test.ts Adds timestamps to fixtures.
app/​test/​unit/​git/​stash-multi-test.ts Tests multiple stashes and path filtering.
app/​test/​helpers/​changes-state-helper.ts Initializes stash collections.
app/​styles/​ui/​changes/​_changes-list.scss Styles the stash list.
app/​src/​ui/​stashing/​stash-diff-viewer.tsx Selects files within a specific stash.
app/​src/​ui/​stash-changes/​stash-and-switch-branch-dialog.tsx Removes overwrite warnings.
app/​src/​ui/​stash-changes/​overwrite-stashed-changes-dialog.tsx Deletes obsolete confirmation dialog.
app/​src/​ui/​repository.tsx Resolves the selected stash by SHA.
app/​src/​ui/​local-changes-overwritten/​local-changes-overwritten-dialog.tsx Allows stashing alongside existing entries.
app/​src/​ui/​dispatcher/​dispatcher.ts Passes stash SHAs and selected paths.
app/​src/​ui/​changes/​sidebar.tsx Supplies stash entries and selection.
app/​src/​ui/​changes/​no-changes.tsx Summarizes the latest stash and count.
app/​src/​ui/​changes/​filter-changes-list.tsx Renders stash rows and checked-file actions.
app/​src/​ui/​app.tsx Updates stash navigation and dialogs.
app/​src/​models/​stash-entry.ts Adds creation timestamps.
app/​src/​models/​popup.ts Removes overwrite popup type.
app/​src/​models/​menu-labels.ts Removes overwrite confirmation flag.
app/​src/​main-process/​menu/​build-default-menu.ts Simplifies stash menu labels.
app/​src/​lib/​stores/​repository-state-cache.ts Initializes stash arrays.
app/​src/​lib/​stores/​git-store.ts Retains and loads multiple stash entries.
app/​src/​lib/​stores/​app-store.ts Coordinates selection, creation, and branch migration.
app/​src/​lib/​menu-update.ts Checks stash collection availability.
app/​src/​lib/​git/​stash.ts Adds timestamps and path-limited stashing.
app/​src/​lib/​app-state.ts Models stash collections and SHA selection.

Review effort: Balanced

Comment thread app/src/lib/git/stash.ts
Comment on lines +168 to +171
if (paths !== undefined && paths.length > 0) {
// Use literal pathspecs so that file names containing glob characters are
// matched exactly.
args.push('--', ...paths.map(path => `:(literal)${path}`))
}

if (await this.createStashAndDropPreviousEntry(repository, currentBranch)) {
if (await this.createStashEntry(repository, currentBranch, filePaths)) {
Comment on lines +1398 to +1399
for (const stashEntry of this.currentBranchStashEntries) {
if (stashEntry.files.kind !== StashedChangesLoadStates.NotLoaded) {
private onStashCheckedChanges = () => {
const paths = this.props.workingDirectory.files
.filter(file => file.isIncludedInCommit())
.map(file => file.path)

This branch has not been deployed

No deployments
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.

Github Desktop does not seem to support multiple stashes. Stash specific file/s or stash selected files

2 participants