Subtubes
Subtubes

Reputation: 16873

Git Stash vs Shelve in IntelliJ IDEA

I am very unfamiliar with the shelve aspect of Git (EDIT: not an aspect of Git, but rather IntelliJ IDEA feature of shelve).

If stash is used to put aside unfinished work what is shelve then? What would you use it for?

For example on Update Project (from VCS menu): Update Project option

one will get (in IntelliJ IDEA 2019.2): Update Project prompt window

Upvotes: 530

Views: 248444

Answers (6)

riyasvaliya
riyasvaliya

Reputation: 825

Shelve is an IntelliJ IDE feature. Stash is a Git feature. Newer versions of git also allows you to stash individual files using

git stash -p

IMO, an advantage Shelve has over plain stash is the ability to shelve changes from multiple repos together

Upvotes: 3

O_K
O_K

Reputation: 1090

Shelf is a JetBrains feature while Stash is a Git feature for same work. You can switch to different branch without commit and loss of work using either of features. My personal experience is to use Shelf.

Upvotes: 6

Hamza Belmellouki
Hamza Belmellouki

Reputation: 2728

I would prefer to shelve changes instead of stashing them if I am not sharing my changes elsewhere.

Stashing is a git feature and doesn't give you the option to select specific files or changes inside a file. Shelving can do that but this is an IDE-specific feature, not a git feature:

enter image description here

As you can see I am able to choose to specify which files/lines to include on my shelve. Note that I can't do that with stashing.

Beware using shelves in the IDE may limit the portability of your patches because those changes are not stored in a .git folder.

Some helpful links:

Upvotes: 42

VonC
VonC

Reputation: 1324228

git shelve doesn't exist in Git.

Only git stash:

  • when you want to record the current state of the working directory and the index, but want to go back to a clean working directory.
  • which saves your local modifications away and reverts the working directory to match the HEAD commit.

You had a 2008 old project git shelve to isolate modifications in a branch, but that wouldn't be very useful nowadays.

As documented in Intellij IDEA shelve dialog, the feature "shelving and unshelving" is not linked to a VCS (Version Control System tool) but to the IDE itself, to temporarily storing pending changes you have not committed yet in changelist.

Note that since Git 2.13 (Q2 2017), you now can stash individual files too.

Upvotes: 460

valex
valex

Reputation: 5789

In addition to previous answers there is one important for me note:

shelve is JetBrains products feature (such as WebStorm, PhpStorm, PyCharm, etc.). It puts shelved files into .idea/shelf directory.

stash is one of git options. It puts stashed files under the .git directory.

Upvotes: 135

Yekver
Yekver

Reputation: 5185

When using JetBrains IDE's with Git, "stashing and unstashing actions are supported in addition to shelving and unshelving. These features have much in common; the major difference is in the way patches are generated and applied. Shelve can operate with either individual files or bunch of files, while Stash can only operate with a whole bunch of changed files at once. Here are some more details on the differences between them."

Upvotes: 261

Related Questions