On Feb 19, 2015, at 04:34, Michael J Gruber wrote:
"git stash save" performs the steps "create-store-reset". Often,
users try to use "stash save" as a way to to save their current state
(index, worktree) before an operation like "checkout/reset --patch"
they
don't feel confident about, and are forced to do "git stash save &&
git
stash apply".
Provide an extra mode that does "create-store" only without the reset,
so that one can "ceckpoint" the sate and keep working on it.
s/sate/state/
Suggested-by: "Kyle J. McKay" <mackyle@xxxxxxxxx>
Signed-off-by: Michael J Gruber <git@xxxxxxxxxxxxxxxxxxxx>
---
Notes:
I'm not sure about how to best expose this mode:
git stash checkpoint
git stash save --checkpoint
Maybe it is best to document the former and rename "--checkpoint"
to "--no-reset"?
Once the user figures out that "save" is really "save-and-reset" I
think "--no-reset" makes more sense.
It certainly seems more discoverable via an explicit "checkpoint"
command though, but that's really just an alias so maybe it's better
left up to the user to make one.
There would need to be some updated docs (git-stash.txt) to go with
the change...
Also, a "safe return" to a checkpoint probably requires
git reset --hard && git stash pop
although "git stash pop" will do in many cases. Should we provide
a shortcut
"restore" which does the reset-and-pop?
What about a shortcut to "reset-and-apply" as well?
I have often been frustrated when "git stash apply" refuses to work
because I have changes that would be stepped on and there's no --force
option like git checkout has. I end up doing a reset just so I can
run stash apply.
What about if git stash apply/pop grokked a --force option? That
would seem to eliminate the need for a "reset-and-pop"/"reset-and-
apply" shortcut while also being useful to non-checkpoint stashes as
well.
git-stash.sh | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/git-stash.sh b/git-stash.sh
index d4cf818..42f140c 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -193,12 +193,16 @@ store_stash () {
}
save_stash () {
+ checkpoint=
keep_index=
patch_mode=
untracked=
while test $# != 0
do
case "$1" in
+ -c|--checkpoint)
+ checkpoint=t
+ ;;
-k|--keep-index)
keep_index=t
;;
@@ -267,6 +271,11 @@ save_stash () {
die "$(gettext "Cannot save the current status")"
say Saved working directory and index state "$stash_msg"
+ if test -n "$checkpoint"
+ then
+ exit 0
+ fi
+
if test -z "$patch_mode"
then
git reset --hard ${GIT_QUIET:+-q}
@@ -576,6 +585,10 @@ save)
shift
save_stash "$@"
;;
+checkpoint)
+ shift
+ save_stash "--checkpoint" "$@"
+ ;;
apply)
shift
apply_stash "$@"
--
Otherwise this looks good. A very small change to add the
functionality.
-Kyle
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html