What's the difference between git stash save and git stash push?

git stash save accepts a single non-option argument — the stash message.

git stash push accepts the message with option -m and accepts a list of files to stash as arguments.


Just to be clear, starting Git 2.15/2.16 (Q1 2018), git stash save has been deprecated in favour of git stash push (though git stash save is still available for the time being).

See commit c0c0c82, commit fd2ebf1, commit db37745 (22 Oct 2017) by Thomas Gummerer (tgummerer).
(Merged by Junio C Hamano -- gitster -- in commit 40f1293, 06 Nov 2017)

stash: mark "git stash save" deprecated in the man page

'git stash push' fixes a historical wart in the interface of 'git stash save'.
As 'git stash push' has all functionality of 'git stash save', with a nicer, more consistent user interface deprecate 'git stash save'.

stash: remove now superfluos help for "stash push"

With the 'git stash save' interface, it was easily possible for users to try to add a message which would start with "-", which 'git stash save' would interpret as a command line argument, and fail.
For this case we added some extra help on how to create a stash with a message starting with "-".

For 'stash push', messages are passed with the -m flag, avoiding this potential pitfall.
Now only pathspecs starting with "-" would have to be distinguished from command line parameters by using "-- --<pathspec>".
This is fairly common in the git command line interface, and we don't try to guess what the users wanted in the other cases.

Because this way of passing pathspecs is quite common in other git commands, and we don't provide any extra help there, do the same in the error message for 'git stash push'.


With Git 2.18 (Q2 2018), the command line completion (in contrib/) has been taught that "git stash save" has been deprecated ("git stash push" is the preferred spelling in the new world) and does not offer it as a possible completion candidate when "git stash push" can be.

See commit df70b19, commit 0eb5a4f (19 Apr 2018) by Thomas Gummerer (tgummerer).
(Merged by Junio C Hamano -- gitster -- in commit 79d92b1, 08 May 2018)

completion: make stash -p and alias for stash push -p

We define 'git stash -p' as an alias for 'git stash push -p' in the manpage. Do the same in the completion script, so all options that can be given to 'git stash push' are being completed when the user is using 'git stash -p --<tab>'.
Currently the only additional option the user will get is '--message', but there may be more in the future.


The command line completion script (in contrib/) tried to complete "git stash -p" as if it were "git stash push -p", but it was too aggressive and also affected "git stash show -p", which has been corrected With Git 2.28 (Q3 2020).

See commit fffd0cf (21 May 2020) by Ville Skyttä (scop).
(Merged by Junio C Hamano -- gitster -- in commit a8ecd01, 09 Jun 2020)

completion: don't override given stash subcommand with -p

Signed-off-by: Ville Skyttä

df70b190 ("completion: make stash -p and alias for stash push -p", 2018-04-20, Git v2.18.0-rc0 -- merge listed in batch #5) wanted to make sure "git stash -p <TAB>" offers the same completion as "git stash push -p <TAB>", but it did so by forcing the $subcommand to be "push" whenever then "-p" option is found on the command line.

This harms any subcommand that can take the "-p" option --- even when the subcommand is explicitly given, e.g. "git stash show -p", the code added by the change would overwrite the $subcommand the user gave us.

Fix it by making sure that the defaulting to "push" happens only when there is no $subcommand given yet.

Tags:

Git

Git Stash