Shelve or stash changes
Sometimes you need to switch between different tasks with things left unfinished and then return back to them. To work on several different features without losing your work, you can shelve or stash your pending changes.
Shelve vs Stash
Stashing changes is very similar to shelving.
Stashes are generated by Git, and can be applied from within JetBrains Rider, or outside it.
Patches with shelved changes are generated by JetBrains Rider and are also applied through the IDE.
Also, stashing involves all uncommitted changes, while when you shelve changes, you can select some of the local changes instead of shelving them all.
Shelve and unshelve changes
Shelving is temporarily storing pending changes you have not committed yet. This is useful, for example, if you need to switch to another task, and you want to set your changes aside to work on them later.
With JetBrains Rider, you can shelve both separate files and entire changelists.
Once shelved, a change can be applied as many times as you need.
Shelve changes
In the Commit tool window , right-click the files or the changelist you want to shelve and select Shelve changes from the context menu.
In the Shelve Changes dialog, review the list of modified files.
In the Commit Message field, enter the name of the shelf to be created and click the Shelve Changes button.
You can also shelve changes silently, without displaying the Shelve Changes dialog. To do this, select the file or changelist you want to shelve and click the Shelve Silently icon on the toolbar or press Ctrl+Shift+H. The name of the changelist containing the changes you want to shelve will be used as the shelf name.
To avoid ending up with numerous shelves with the same name (such as Default, for example), you can drag a file or a changelist from the Commit to <branch> tab to the Shelf tab of the Commit tool window, wait for a second until it's activated, and edit the new shelf name after releasing the mouse button.
Unshelve changes
Unshelving is moving postponed changes from a shelf to a pending changelist. Unshelved changes can be filtered out from view or removed from the shelf.
In the Shelf tab, select the changelist or the files you want to unshelve.
Press Ctrl+Shift+U or choose Unshelve from the context menu of the selection.
In the Unshelve Changes dialog, specify the changelist you want to restore the unshelved changes to in the Name field. You can select an existing changelist from the list or enter the name for a new changelist to be created. You can enter the description of the new changelist in the Comment field (optional).
If you want to make the new changelist active, select Set active. Otherwise, the current active changelist remains active.
If you want JetBrains Rider to save the context of a task associated with the new changelist when deactivated and restore the context when the changelist becomes active, select the Track context option (refer to tasks and contexts for details) .
If you want to remove the changes you are about to unshelve, select the Remove successfully applied files from the shelf option. The unshelved files will be removed from this shelf, added to another changelist, and marked as applied. They will not be removed completely until deleted explicitly by clicking on the toolbar or selecting Clean Already Unshelved from the context menu.
Click OK. If conflicts occur between the patched version and the current version, resolve them as described in Resolve Git conflicts.
You can also unshelve changes silently, without displaying the Unshelve Changes dialog. To do this, select a file or a changelist you want to unshelve and click the Unshelve Silently icon on the toolbar or press Ctrl+Alt+U. The unshelved files will be moved to the active pending changelist.
You can also drag a file or a changelist from the Shelf tab to the Commit to <branch> tab to unshelve it silently. If you drag it holding the Ctrl key, it will be copied to the Commit to branch tab but also kept in the shelf.
Discard shelved changes
In the Shelf view, select the changelist that contains the changes you do not want to keep anymore.
Right-click the changelist and choose Delete from the context menu or press Delete.
Restore unshelved changes
JetBrains Rider lets you reapply unshelved changes if necessary. All unshelved changes can be reused until they are removed explicitly by clicking the icon on the toolbar or selecting Clean Already Unshelved from the context menu.
Make sure that the Show Already Unshelved toolbar option is enabled.
Select the files or the shelf you want to restore.
From the context menu of the selection, choose Restore.
Apply external patches
You can import patches created inside or outside JetBrains Rider and apply them as shelved changes.
In the Shelf view, choose Import Patches from the context menu.
In the dialog that opens, select the patch file to apply. The selected patch appears in the Shelf tab as a shelf.
Select the newly added shelf with the patch and choose Unshelve Changes from the context menu of the selection.
Automatically shelve base revision
It may be useful to configure JetBrains Rider to always shelve base revisions of files that are under Git version control.
Press Ctrl+Alt+S to open settings and then select
.Select the Shelve base revisions of files under distributed version control systems option.
If this option is enabled, the base revision of files will be saved to a shelf that will be used during a 3-way merge if applying the shelf leads to conflicts. If it is disabled, JetBrains Rider will look for the base revision in the project history, which may take a while; moreover, the revision that the conflicting shelf was based on may be missing (for example, if the history was changed as a result of the rebase operation).
Change the default shelf location
By default, the shelf directory is located under your project directory. However, you may want to change the default shelf location. This can be useful, for example, if you want to avoid deleting shelves accidentally when cleaning up your working copy or if you want to store them in a separate repository allowing shelves to be shared among your team members.
Press Ctrl+Alt+S to open settings and then select
.Click Change Shelves Location and specify the new location in the dialog that opens.
If necessary, select Move shelves to the new location to move existing shelves to the new directory.
Watch this video tutorial on how to benefit from shelves to be able to switch to a different task without losing unfinished work:
Stash changes
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.
You can apply a stash to an existing branch or create a new branch on its basis.
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.
You cannot apply a stash to a "dirty" working copy, that is a working copy with uncommitted changes.
Save changes to a stash
In the main menu, go to
.In the Stash dialog that opens, select the appropriate Git root and make sure that the correct branch is checked out.
In the Message field describe the changes you are about to stash.
To stash local changes and bring the changes staged in the index to your working tree for examination and testing, select the Keep index option.
Click Create Stash.
Apply a stash
In the main menu, go to
.Select the Git root where you want to apply a stash, and make sure that the correct branch is checked out.
Select the stash you want to apply from the list.
If you want to check which files are affected in the selected stash, click View.
To remove the selected stash after it is applied, select the Pop stash option.
To apply stashed index modifications as well, select the Reinstate Index option.
If you want to create a new branch on the basis of the selected stash instead of applying it to the branch that is currently checked out, type the name of that branch in the As new branch field.
To remove a stash, select it in the list and click Drop. To remove all stashes, click Clear.