git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Phillip Wood <phillip.wood123@gmail.com>
Cc: "J. Dettweiler" <git.vger.kernel.org@dettweb.de>,
	 git@vger.kernel.org, "D. Ben Knoble" <ben.knoble@gmail.com>
Subject: Re: [FEATURE] Proposal: git stash --only-unstaged
Date: Sun, 17 Aug 2025 09:08:38 -0700	[thread overview]
Message-ID: <xmqqfrdqkk1l.fsf@gitster.g> (raw)
In-Reply-To: <60f38225-2bcb-4383-be40-36c7b02cf38c@gmail.com> (Phillip Wood's message of "Sat, 16 Aug 2025 17:12:47 +0100")

Phillip Wood <phillip.wood123@gmail.com> writes:

> To use it create your stash with "git stash push --keep-index" and then
> use the script to pop the unstaged changes rather than using "git stash
> pop". If the script proves to be useful then perhaps we could add an
> "--unstaged" option to "git stash pop"

Hmph, would the behaviour useful enough that it should be always
enabled, without any new option?  I strongly suspect that those who
worked on adding "--keep-index" option did not expect the user to be
mucking with the working tree files while "testing the staged stuff
by updating the working tree files to match it and nothing else",
and as long as the end-user stays within that originally designed
use case, nothing changes for them, no?

Thanks.

(the script left for reference without comments below).

> ---- 8< ----
> #!/bin/sh
>
> USAGE="${0##*/} [<stash>]"
> SUBDIRECTORY_OK=1
> . "$(git --exec-path)/git-sh-setup"
> cd_to_toplevel
> require_clean_work_tree stash-pop-unstaged
>
> LF='
> '
> stash="${1:-stash@{0}}"
> if ! stash_oid="$(git rev-parse --verify --quiet "$stash")" ||
>    ! oid1="$(git rev-parse --verify --quiet $stash_oid^1)" ||
>    ! oid2="$(git rev-parse $stash_oid^2^@ 2>/dev/null)" ||
>    test "$oid1" != "$oid2"
> then
>     die "error: '$stash' does not look like a stash commit"
> fi
> merge_output="$(git merge-tree --merge-base=$stash_oid^2: HEAD: $stash_oid:)"
> status=$?
> if test $status = 0
> then
>     tree=$merge_output
>     conflict_info=
>     messages=
> elif test $status = 1
> then
>     merge_output="$merge_output$LF"
>     tree="${merge_output%%$LF*}"
>     conflict_info="${merge_output%%$LF$LF*}"
>     conflict_info="${conflict_info#*$LF}"
>     messages="${merge_output#*$LF$LF}"
> else
>     exit 128
> fi
> git read-tree --index-output="$GIT_DIR/stash-pop-index" -m -u HEAD $tree &&
> rm "$GIT_DIR/stash-pop-index" &&
> if test -n "$conflict_info"
> then
>     printf '%s' "$messages" >&2
>     printf '%s\n' "$conflict_info" | git update-index --index-info
> else
>     git stash drop "$stash"
> fi

  reply	other threads:[~2025-08-17 16:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-13  8:51 [FEATURE] Proposal: git stash --only-unstaged J. Dettweiler
2025-08-13 15:30 ` Junio C Hamano
2025-08-13 17:02 ` D. Ben Knoble
2025-08-16 16:12 ` Phillip Wood
2025-08-17 16:08   ` Junio C Hamano [this message]
2025-08-18 15:14     ` Phillip Wood
2025-08-18 23:41       ` Ben Knoble
2025-08-29 13:06         ` Phillip Wood
2025-08-29 13:30           ` D. Ben Knoble
2025-09-16 11:03             ` Phillip Wood
2025-09-16 17:10               ` D. Ben Knoble

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqfrdqkk1l.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=ben.knoble@gmail.com \
    --cc=git.vger.kernel.org@dettweb.de \
    --cc=git@vger.kernel.org \
    --cc=phillip.wood123@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).