Git Stash vs Shelve in IntelliJ IDEA

152,805

Solution 1

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.

Solution 2

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."

Solution 3

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.

Solution 4

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:

Solution 5

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.

Share:
152,805
Subtubes
Author by

Subtubes

Updated on July 08, 2022

Comments

  • Subtubes
    Subtubes almost 2 years

    I am very unfamiliar with the shelve aspect of Git. 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)

    enter image description here

    one will get (in IntelliJ IDEA 2019.2)

    enter image description here

  • Subtubes
    Subtubes over 9 years
    Turns out I misunderstood the concept. I thought it was a Git command when in fact it is a third party thing from IntelliJ IDEA. I could not find the git docs for it so thought I was missing something. jetbrains.com/idea/help/shelving-and-unshelving-changes.html
  • barbara.post
    barbara.post about 9 years
    Your doc link indicates that "shelves" are set of changes (patch) managed by IntelliJ IDE only, unlinke "stashes" that are standard things managed by Git. So avoid shelves.
  • Dmitry Davydov
    Dmitry Davydov over 7 years
    It seems that shelve is more flexible than git stash.
  • The Vee
    The Vee over 7 years
    @DmitryDavydov There's git stash -p which trumps both. Unfortunately only in the command line.
  • Dmitry Davydov
    Dmitry Davydov over 7 years
    @TheVee yes it's very similar to shelve in terms of functionality, thanks for info.
  • kyb
    kyb about 7 years
    Actually, since Git 2.13 (Q2 2017) you can stash individual files... read more
  • kyb
    kyb about 7 years
    And there is also interactive more git stash -p. read more
  • Jerry Chin
    Jerry Chin almost 7 years
    @barbara.post avoiding shelves? are you sure it's the right thing to do in case I want to stash only one modified file?
  • digender mahara
    digender mahara over 6 years
    @jerry chin shelve is better than stash in your case. I wish if shelve was present in git. Webstorm sucks out the RAM. It would be usefull if git had it we could run it in cmd line
  • ingkevin
    ingkevin over 6 years
    I found shelve very useful when you have a patch of changes that you want to apply every time that you want to auto generate documentation for example. Shelve will create a file within .idea/shelve and you can add it to you VCS and share it with all your team so they can apply those changes and run the same tasks.
  • AmerllicA
    AmerllicA almost 6 years
    Thanks for clarify this critical question.
  • smaudet
    smaudet almost 6 years
    There is a common use case that shelve has that stash doesn't address - dealing with problematic co-workers/company practices. Its possible for complete garbage to get added to your repository and for to be not kosher to 'fix' it because of somebody's insanity. The alternative is something like git stash && <your actual command> && git stash pop but that sucks. Auto-shelve and apply is closer to what we need.
  • VonC
    VonC almost 6 years
    @smaudet Is it like ingkevin's comment? (stackoverflow.com/questions/28008139/git-shelve-vs-stash/…)
  • smaudet
    smaudet over 5 years
    @VonC similar not the same - I have a use case where the projects I'm using have settings I require that can't be committed because they 'aren't standard'. And half a dozen other use cases I've come across involving things like needing modify build files etc. for local development vs dev/test/prod.