What is the difference between IntelliJ's Shelve and Git stash?
Solution 1
From the IntelliJ documentation:
In the Git integration, in addition to shelving and unshelving, "stashing" and "unstashing" are supported respectively. These features have much in common, the only difference is in the way patches are generated and applied.
- Patches with stashed changes are generated by Git itself. To apply them later, you do not need IntelliJ IDEA.
- Patches with shelved changes are generated by IntelliJ IDEA. Normally, they are also applied through the IDE. Applying shelved changes outside IntelliJ IDEA is also possible but requires additional steps.
Solution 2
They are pretty similar except:
- You can't use shelve outside IDE, because it is Intellij's feature.
- Git stash works only with entire working directory and index. IntelliJ's shelve can work with individual files and changelists (another IntelliJ's feature). As you can see, for example, here, sometimes it is necessary.
- Idea has better built-in support for shelve. Working with git stash is more straightforward. In particular, you can shelve\unshelve your changes or review shelved files from version control tool window.
Also, IMHO, shelve works slightly faster, especially in a big project, when lots of files were changed.
See the documentation for more info.
Solution 3
One distinct advantage that Intellij's Shelve has over plain Git's stash is that using Shelve, you can save changes belonging to multiple repos in one changelist. Using stash, you would need to stash/unstash in each repo individually. This is very useful in a large project with multiple modules (each having its own repo) where a particular feature work may cut across multiple modules (and therefore multiple repos)
Solution 4
Here is what Documentation Says
Stashing changes is very similar to shelving. The only difference is in the way patches are generated and applied. Stashes are generated by Git, and can be applied from within IntelliJ IDEA, or outside it. Patches with shelved changes are generated by IntelliJ IDEA and are also applied through the IDE. Also, stashing involves all uncommitted changes, while when you put changes to a shelf, you can select some of the local changes instead of shelving them all.
Daniel Compton
Building private Maven repositories at Deps and public ones at Clojars. Software developer, primarily focused on Clojure, ClojureScript, re-frame, and Datomic.
Updated on December 08, 2020Comments
-
Daniel Compton over 3 years
IntelliJ supports git stashes as well as it's own built in shelve command. These seem to be almost identical in purpose and utility. What is the difference between them?
-
MaxiWheat over 7 yearsWell, so what are the advantages of shelving since it is just "less compatible" with plain git ?
-
Daniel Compton over 7 yearsIt seems like shelving would be useful if you used a VCS which didn't have a native stash style feature. If you use git, I can't see any real benefits.
-
vikingsteve almost 7 yearsI find right clicking on a changeless to shelve it quickly to be very useful. As you allude to, I find it slightly quicker.
-
Chaoz over 5 years"Git stash works only with entire working directory and index" - this is wrong. Git stash can stash individual files and folders as well - eg.:
git stash -- foo/bar.txt
-
Martin Melka over 5 yearsThe 'real benefits' are listed in the answer by id.bobr. The main thing for me is being able to choose which files/chunks to stash, much like when committing.
-
Deric Lima about 5 yearsSince Git 2.13, is possible to stash individual files with
git stash push
. -
itachi over 3 yearsShelve gives you a much better overview of what's inside and what differs. It's easier to apply only some parts of the changed files. At first I wasn't convinced to this feature, but now I'm using it more often than stash.
-
Lost Crotchet almost 3 years@itachi but can you edit the shelved change lists? It seems to me that they can't be and instead they have to be recreated?
-
itachi almost 3 years@LostCrotchet In order to change something that's already shelved, you have to un-shelve it firstly; that's the only way.