What's the difference between git stash save a

2020-01-30 07:01发布

问题:

When should I use git stash save instead of git stash push and vice-versa?

回答1:

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.



回答2:

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.



标签: git git-stash