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

[RFD/PATCH] stash: introduce checkpoint mode

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Feb 19, 2015, 12:34 UTC
Message-ID
<dbd1aae0508bd72dc3b21fabda4c420eef487720.1424349039.git.git@drmicha.warpmail.net>
In-Reply-To
<54E5C27E.9060109@drmicha.warpmail.net>

"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.

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"?
    
    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?
 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 "$@"
-- 
2.3.0.191.ge77e8b9
Previous: Michael J GruberNext: Kyle J. McKay
Message 8 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.