Git Stash vs Shelve in IntelliJ IDEA
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:
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:
- https://www.jetbrains.com/help/idea/shelving-and-unshelving-changes.html
- https://www.jetbrains.com/help/idea/work-on-several-features-simultaneously.html
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.
Subtubes
Updated on July 08, 2022Comments
-
Subtubes almost 2 years
I am very unfamiliar with the
shelve
aspect of Git. Ifstash
is used to put aside unfinished work what isshelve
then? What would you use it for?For example on Update Project (from VCS menu)
one will get (in IntelliJ IDEA 2019.2)
-
Subtubes over 9 yearsTurns 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 about 9 yearsYour 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 over 7 yearsIt seems that shelve is more flexible than git stash.
-
The Vee over 7 years@DmitryDavydov There's
git stash -p
which trumps both. Unfortunately only in the command line. -
Dmitry Davydov over 7 years@TheVee yes it's very similar to shelve in terms of functionality, thanks for info.
-
kyb about 7 yearsActually, since Git 2.13 (Q2 2017) you can stash individual files... read more
-
kyb about 7 yearsAnd there is also interactive more
git stash -p
. read more -
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 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 over 6 yearsI 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 almost 6 yearsThanks for clarify this critical question.
-
smaudet almost 6 yearsThere 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 almost 6 years@smaudet Is it like ingkevin's comment? (stackoverflow.com/questions/28008139/git-shelve-vs-stash/…)
-
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.