Stashing and Unstashing Changes
On this page:
- Stashing and unstashing
- Stashing vs shelving
Stashing and unstashing
Sometimes it may be necessary to revert your working copy to match the HEAD commit but you do not want to lose the work you have already done. This may happen if you learn that there are upstream changes that are possibly relevant to what you are doing, or if you need to make some urgent fixes.
Stashing involves recording the difference between the HEAD commit and the current state of the working directory (stash). Changes to the index can be stashed as well.
Unstashing involves applying a stored stash to a branch.
A stash can be applied as many times as you need to any branch you need, just switch to the required branch. Keep in mind that:
- Applying a stash after a series of commits results in conflicts that need to be resolved.
- A stash cannot be applied to a "dirty" working copy, that is a working copy to which changes have been made since the latest commit.
You can store stashes in a list as long as you need and remove them from the list when necessary.
Saving changes to a new stash
- From the main menu, choose . The Stash dialog box opens.
- Select the relevant Git root and make sure that the correct branch is checked out.
- In the Message text box, describe the changes to be stashed.
Applying a stash
To apply a stash to the same branch
- From the main menu, choose . The Unstash Changes dialog box opens.
- Select the Git root where you want to apply a stash and make sure that the correct branch is checked out.
- In the Stashes list, select the relevant stash.
- Click the View button to open the Paths affected in commit dialog box and find out which files are affected in the selected stash.
- Specify additional unstash options:
To create a new branch on the basis of a stash
Stashing vs shelving
The only difference is in the way patches are generated and applied: