git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFD/PATCH] stash: introduce checkpoint mode

From
Kyle J. McKay <mackyle@gmail.com>
Date
Feb 19, 2015, 13:58 UTC
Message-ID
<8AAD6FE6-75C1-4BA2-8667-4DF8BF6B1EE4@gmail.com>
In-Reply-To
<dbd1aae0508bd72dc3b21fabda4c420eef487720.1424349039.git.git@drmicha.warpmail.net>
On Feb 19, 2015, at 04:34, Michael J Gruber wrote:
Show 10 quoted lines
> "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/
Show 12 quoted lines
> Suggested-by: "Kyle J. McKay" <mackyle@gmail.com>
> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
> ---
>
> 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...

Show 7 quoted lines
>    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.

Show 48 quoted lines
> 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
Previous: Michael J GruberNext: Junio C Hamano
Message 9 of 11 in “Experience with Recovering From User Error (And suggestions for improvements)”
  1. Armin RonacherFeb 16, 2015
  2. Ævar Arnfjörð BjarmasonFeb 16, 2015
  3. Ævar Arnfjörð BjarmasonFeb 16, 2015
  4. Duy NguyenFeb 16, 2015
  5. Armin RonacherFeb 16, 2015
  6. Michael J GruberFeb 18, 2015
  7. Michael J GruberFeb 19, 2015
  8. stash: introduce checkpoint modeMichael J Gruber, Feb 19, 2015
  9. Kyle J. McKayFeb 19, 2015
  10. Junio C HamanoFeb 19, 2015
  11. Kyle J. McKayFeb 19, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.