Stashing

Stashes are a convenient way to temporarily store the current Working Tree changes (either all changes, or just selected changes) aside, and then re-apply them later. For example, stashes are useful if you realize that you have started making changes to files in the Working Tree without first checking out the correct branch.

Creating a Stash

In the Log and Working Tree windows, use Local -> Stash All to stash away all local modifications of your Working Tree, and optionally enter a Message to describe the stash. To stash away selected files, use Local -> Stash Selection. Saved stashes appear in the Branches view.

The Standard Window also provides stash commands with Advanced functionality. Saved stashes appear in its Stashes view.

By default, the saved changes are cleared from the Index and Working Tree, allowing checkout of another branch. In either save dialog, + Keep Index leaves staged changes in the Index. Use + Keep Working Tree to create a stash while keeping your working-tree changes and their staging state.

In the Log and Working Tree windows, use Quick Stash All from the stash action menu to save changes without opening the save dialog.

With Stash Selection, staged files outside your selection are also included in the stash.

Note

In the Log and Working Tree windows, enable Include untracked files to include untracked files with Stash All and Quick Stash All. Stash All in the Standard Window always includes untracked files. Stash Selection includes selected untracked files regardless of this preference. Depending on the operating system it may take significantly longer to execute the operation.

Applying a Stash

To apply a stash to the current state of the Working Tree, right-click the stash and select Apply Stash to re-apply the contained changes to your Working Tree (e.g. after switching branches).

In the Standard Window, commit or stash existing changes, including untracked files, before invoking Apply Stash.

Choose Apply to keep the stash or Apply & Drop to remove it after applying the changes. Select Restore Index to restore the saved staging state along with file contents.

Note

If applying with Restore Index fails while the Index and working tree remain clean, SmartGit can offer Try Without Restoring Index.

Note

Set the Low-Level Property standard.stashApply.allowDirtyWt to true to bypass the Standard Window clean-tree check before opening Apply Stash.

Other Stash Commands

The following commands can be executed by right-clicking on a Stash (under Stashes in the Branch View):

  • To get rid of obsolete stashes, use Drop Stash; however, be aware that this will irretrievably delete any changes which are stored in the stash.
  • The Rename Stash command allows you to change the displayed stash message.
  • Compare with HEAD / Compare with Selected Commit allows you to compare the contents of the stash against the HEAD / selected commit, respectively.
  • Copy Message copies the stash message of the selected Stash into the OS clipboard.

Drop Stash and Rename Stash are also available in the Standard Window’s Stashes view.

  • git stash push: --keep-index, --include-untracked, --message.
  • git stash apply, optionally with --index.
  • git stash pop, optionally with --index.
  • git stash drop <stash>.
  • git stash store: -m for Rename Stash.