threads / discuss / 65142

Git reference git stash

Subject: Git reference git stash

## tl;dr

5 messages between Mar 5, 2026 and Mar 6, 2026.

replies: 4people: 4as markdown or json

Aron Sigfridsson· Mar 5, 2026, 20:07 UTC · lore
Hi!

In the reference for git stash there is a section that specifies the use of the pathspec option. It refers you to the gitglossary section about pathspec for further information. In the glossary it states: "See the documentation of each command for whether paths are relative to the current directory or toplevel"

In the documentation for git stash I can't find any information about whether it is top level or relative to current directory. Am I missing something, or is the information not there?

Thank you for your work!
Aron
Mirko Faina· Mar 6, 2026, 02:09 UTC · re: Aron Sigfridsson · lore

Re: Git reference git stash

It doesn't seem to be specified at all, but from a quick test you can see for yourself that "git stash push <pathspec>" uses relative paths from the current directory and not the toplevel one.

To be sure on what's the relative path to use you can check the output from "git status".

Maybe it should be added to the documentation for "git stash".
Mirko Faina· Mar 6, 2026, 02:31 UTC · re: Mirko Faina · lore

Re: Git reference git stash

On Fri, Mar 06, 2026 at 03:09:15AM +0100, Mirko Faina wrote:
Show 8 quoted lines
> It doesn't seem to be specified at all, but from a quick test you can
> see for yourself that "git stash push <pathspec>" uses relative paths
> from the current directory and not the toplevel one.
> 
> To be sure on what's the relative path to use you can check the output
> from "git status".
> 
> Maybe it should be added to the documentation for "git stash".

Looking at the docs for other commands that use pathspec, it doesn't look like any of them explicitly say if it's toplevel or relative neither. I suppose the author thought it was obvious which one it was, besides, it can be easily checked just by trying out the command.

erik88· Mar 6, 2026, 12:29 UTC · re: Mirko Faina · lore

Re: Git reference git stash

On 26/03/06 03:31AM, Mirko Faina wrote:
Show 6 quoted lines
> 
> Looking at the docs for other commands that use pathspec, it doesn't
> look like any of them explicitly say if it's toplevel or relative
> neither. I suppose the author thought it was obvious which one it was,
> besides, it can be easily checked just by trying out the command.
> 
Pretty sure git stash push is the only one which does pathspec
    git stash -h
    usage: git stash list [<log-options>]
       ...
       or: git stash [push [-p | --patch] [-S | --staged] [-k | --[no-]
                     [-u | --include-untracked] [-a | --all] [(-m | --m
                     [--pathspec-from-file=<file> [--pathspec-file-nul]
                     [--] [<pathspec>...]]
and pretty sure it's relative.

Sadly, git stash list does not allow a pathspec, despite the [<log-options>]. But if you want you can do

    git log stash [<log-options>] [--] [<pathspec>]
instead, which is handy sometimes.
Junio C Hamano· Mar 6, 2026, 21:50 UTC · re: erik88 · lore

Re: Git reference git stash

erik88 <erik88@gmail.com> writes:
Show 11 quoted lines
> Pretty sure git stash push is the only one which does pathspec
>
>     git stash -h
>     usage: git stash list [<log-options>]
>        ...
>        or: git stash [push [-p | --patch] [-S | --staged] [-k | --[no-]
>                      [-u | --include-untracked] [-a | --all] [(-m | --m
>                      [--pathspec-from-file=<file> [--pathspec-file-nul]
>                      [--] [<pathspec>...]]
>
> and pretty sure it's relative.

In a very early days of Git, I suspect there were, but in modern version with ":/" (or :(top)" pathspec magic, I do not think of a need for any command (unless it cannot work from anywhere except for the top level of the working tree for some reason) to insist taking pathspec from the top, not relative to the directory where the user is at. It would break the <TAB>-completion if anything insists that the pathspec must be relative to the top-level.

It may be a very good exercise (this can be done even by somebody relatively new to the community, I think) to see if anything still insists <pathspec> from the top. And change the documentation of the pathspec to say "unless specifically spelled out in each command's documentation, pathspec elements are taken as relative to the current directory" or something.

Show 6 quoted lines
> Sadly, git stash list does not allow a pathspec, despite the
> [<log-options>]. But if you want you can do
>
>     git log stash [<log-options>] [--] [<pathspec>]
>
> instead, which is handy sometimes.

← back to recent threads