Hi Kazumasa,
On Mon, Nov 30, 2026 at 1:12 AM 重田一聖 <kazu…@kanamei.com> wrote:
>
> Hi,
>
> While preparing an RFC about adding option support to
> `git stash create`, I was looking more closely at `-u` and
> `-a` when I noticed something interesting about how they
> behave in `git stash push` and `git stash save`.
>
> The `-u` option includes untracked files, while `-a` includes
> both untracked and ignored files.
>
> However, when both options are given, their order matters:
>
> git stash push -u -a
> untracked and ignored files
>
> git stash push -a -u
> untracked files only
>
> Both `--no-include-untracked` and `--no-all` cancel the
> selection of untracked and ignored files, regardless of
> whether `-u` or `-a` was specified earlier:
>
> git stash push -a --no-include-untracked
> neither untracked nor ignored files
>
> git stash push -a --no-include-untracked -u
> untracked files only
>
> The documentation explains each option separately, but not what
> happens when they are combined. This may be confusing for users.
On the one hand, this is somewhat convenient for aliases that include
one of the two flags but the user wishes to override the choice when
invoking the alias.
OTOH, this seems a bit of a niche corner for such a thing, and while
"last one wins" is clear, it being undocumented is definitely
confusing.
> (A) Make `-a` take precedence over `-u` when both are enabled,
> regardless of order.
>
> Both `-u -a` and `-a -u` would include untracked and ignored
> files. Today, `-a -u` leaves ignored files alone.
>
> (B) Treat `-u` and `-a` as mutually exclusive, as `git add`
> does with `-u` and `-A`.
>
> If both remain enabled after option parsing, this would be an
> error. Both `-u -a` and `-a -u` would then fail, whereas they
> are currently accepted.
>
> For (A) and (B), I'll assume `-u` and `-a` are tracked
> separately, with each negated option canceling only its
> corresponding positive option. This seems easier to
> reason about, so I'll use that assumption here. A
> negated option would not cause an error even if its
> positive option had not been given.
>
> For example, `-a -u --no-all` would leave `-u` enabled,
> selecting untracked files only, whereas it currently
> selects neither class.
>
> Similarly, `-a --no-include-untracked` would leave
> `-a` enabled and select both untracked and ignored files,
> unlike today.
>
> (C) Add `-X` (or `--include-ignored`) for ignored files only,
> similar to `git clean -X`.
>
> For (C), I'll consider `-u` and `-X` as two independent
> flags instead.
>
> Here, `-a` would be an alias for `-u -X`, and `--no-all`
> would be an alias for `--no-include-untracked` and
> `--no-include-ignored` together.
>
> This would allow untracked and ignored files to be selected
> independently. Both `-u -a` and `-a -u` would select both
> classes.
>
> The negated options would also work independently.
> One possible advantage is that each option's effect would
> follow directly from its meaning, even in combinations.
> For example:
>
> -a --no-include-untracked
> ignored files only
>
> -a --no-include-ignored
> untracked files only
>
> -a --no-all
> neither untracked nor ignored files
>
> `-a --no-include-untracked` illustrates the difference:
> unlike (A) and (B), (C) would remove untracked files from
> the selection, as the negated option suggests. This would
> also differ from today's behavior.
>
> To compare some less obvious combinations, I made this
> table. I assume the documentation would describe (B)'s
> conflict error and (C)'s aliases. Each cell shows the
> result and whether I find it intuitive (Yes/No):
>
> Option sequence Current A B C
> -u -a UI/Yes UI/Yes Err/Yes UI/Yes
> -a -u U/No UI/Yes Err/Yes UI/Yes
> -a --no-include-untracked -/No UI/No UI/No I/Yes
> -a -u --no-all -/Yes U/No U/No -/Yes
> -u -a --no-all -/Yes U/No U/No -/Yes
> -a -u --no-include-untracked -/No UI/No UI/No I/Yes
> -a --no-include-untracked -u U/No UI/Yes Err/Yes UI/Yes
> -a --no-all -u U/Yes U/Yes U/Yes U/Yes
> -a --no-include-ignored N/A/- N/A/- N/A/- U/Yes
>
> Here, U means untracked files, I ignored files, UI both,
> and "-" neither. Err means an error; N/A means the option
> is not available.
>
> Writing this out, I find (C) more consistent than I had
> expected, and I'm tempted to favor it. But it would change
> the behavior of some existing combinations, so backward
> compatibility is still a concern.
>
> (I'm not sure how difficult (C) would be to implement.)
>
> For now, I think documenting the current behavior would
> be the better step. If needed, we could continue to discuss
> possible changes separately. What do you think?
[editing before sending: I wrote ~95% of the below having skipped the
(C) idea, since it seemed like a lot of words=complexity, and then
ended up reinventing it! I've left the whole thing untouched except to
mention that it's equivalent, since it shows there is a somewhat
concise way to lay out the idea.]
All of this suggests to me that "--all" is doing too much. It seems
like what we really want are 2 options "--include-untracked" and
"--include-ignored" (which can be combined/negated independently).
Then "--all" and its negation are typing shortcuts for specifying both
in positive or negative form, and processing the command line in order
explains the results:
-a --no-include-untracked #=> --include-ignored
-a -u #=> -a
-u -a #=> -a
etc.
I think this is similar (nay, on reread---identical!) to your proposal
(C)? This is also a behavior change, though. I don't think we have any
tests pinning down the behavior of the combined options:
git grep -e -a t/*stash*
git grep include-unt t/*stash*
git grep -e -u t/*stash*
doesn't appear to show any where both are used. And as you point out,
it's not documented.
So, I'd be in favor of simplifying the interaction along these lines
(or making their combined use an error) even if that might hurt some
scripts, but that's just me.
--
D. Ben Knoble