# 'git stash push -- {dir}' puts files in stash that are outside of {dir}

4 messages from 2023-07-26 to 2023-07-26. Participants: Yuri, Junio C Hamano.
Thread: https://gitlist.dev/t/60030

## Yuri, 2023-07-26 17:05

Subject: 'git stash push -- {dir}' puts files in stash that are outside of {dir}
Message-ID: <5fce9c4f-0ea7-9393-4a30-ddd66946661d@tsoft.com>
URL: https://gitlist.dev/e/5fce9c4f-0ea7-9393-4a30-ddd66946661d%40tsoft.com

```
I am in the FreeBSD ports repository.

I run this command:

$ git stash push -m "gh-print-tuple" -- Mk

But then 'git show' shows that the top stash entry also has other files:

$ git stash show -p stash@{0} | grep diff
diff --git a/Mk/Scripts/print-submodule-gh_tuple.awk 
b/Mk/Scripts/print-submodule-gh_tuple.awk
diff --git a/Mk/Scripts/print-submodule-gh_tuple.sh 
b/Mk/Scripts/print-submodule-gh_tuple.sh
diff --git a/Mk/bsd.sites.mk b/Mk/bsd.sites.mk
diff --git a/audio/triceratops-lv2/files/patch-synth.cpp 
b/audio/triceratops-lv2/files/patch-synth.cpp
diff --git a/cad/scotch/distinfo b/cad/scotch/distinfo
diff --git 
a/cad/scotch/files/patch-Make.inc_Makefile.inc.i686__pc__freebsd 
b/cad/scotch/files/patch-Make.inc_Makefile.inc.i686__pc__freebsd
diff --git 
a/cad/scotch/files/patch-Make.inc_Makefile.inc.x86-64__pc__freebsd 
b/cad/scotch/files/patch-Make.inc_Makefile.inc.x86-64__pc__freebsd
diff --git a/x11/darktile/Makefile b/x11/darktile/Makefile
diff --git a/x11/darktile/distinfo b/x11/darktile/distinfo
diff --git 
a/x11/darktile/files/patch-vendor_github.com_kr_pty_ztypes__freebsd__arm64.go 
b/x11/darktile/files/patch-vendor_github.com_kr_pty_ztypes__freebsd__arm64.go
diff --git 
a/x11/darktile/files/patch-vendor_github.com_riywo_loginshell_loginshell.go 
b/x11/darktile/files/patch-vendor_github.com_riywo_loginshell_loginshell.go
diff --git a/x11/darktile/pkg-descr b/x11/darktile/pkg-descr


Why do files that are not under Mk get into stash?



Thanks,

Yuri



```

## Junio C Hamano, 2023-07-26 17:29

Subject: Re: 'git stash push -- {dir}' puts files in stash that are outside of {dir}
Message-ID: <xmqqsf9ad1ju.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqsf9ad1ju.fsf%40gitster.g
In-Reply-To: <5fce9c4f-0ea7-9393-4a30-ddd66946661d@tsoft.com>

```
Yuri <yuri@tsoft.com> writes:

> I am in the FreeBSD ports repository.
>
> I run this command:
>
> $ git stash push -m "gh-print-tuple" -- Mk
>
> But then 'git show' shows that the top stash entry also has other files:
>
> $ git stash show -p stash@{0} | grep diff

Not offering a solution, as a quick test or two in my environment do
not reproduce this problem [*].  But instead of the above command,
which will show matches on any line that has "diff" in the "-p"
output, perhaps

    $ git stash show --stat

is easier to see?

Are there configuration variables set to affect the behaviour of the
"git stash" command in your environment that I do not have (I have
nothing in "git config -l | grep stash" output), which may be
affecting why it does not reproduce for me?

> Why do files that are not under Mk get into stash?


[Footnote]

* Admittedly I didn't recall we had pathspec support to "git stash
  push" so consider me no longer an expert in this area ;-).

```

## Yuri, 2023-07-26 17:36

Subject: Re: 'git stash push -- {dir}' puts files in stash that are outside of {dir}
Message-ID: <792f71bb-2b9a-2e2b-80ea-9e3afd9fbfb4@tsoft.com>
URL: https://gitlist.dev/e/792f71bb-2b9a-2e2b-80ea-9e3afd9fbfb4%40tsoft.com
In-Reply-To: <xmqqsf9ad1ju.fsf@gitster.g>

```
On 7/26/23 10:29, Junio C Hamano wrote:
> Are there configuration variables set to affect the behaviour of the
> "git stash" command in your environment that I do not have (I have
> nothing in "git config -l | grep stash" output), which may be
> affecting why it does not reproduce for me?


"git config -l | grep stash" doesn't print anything.

Interestingly, the command 'git stash push -- Mk' puts intended and unintended files in stash, but the changes in unintended files (ones not under Mk) stay, while changes in the intended files are gone, as expected.

Clearing all changes and doing 'git stash pop && git stash push -- Mk' reproduces the problem.


Yuri


```

## Junio C Hamano, 2023-07-26 18:14

Subject: Re: 'git stash push -- {dir}' puts files in stash that are outside of {dir}
Message-ID: <xmqqo7jyczgj.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqo7jyczgj.fsf%40gitster.g
In-Reply-To: <792f71bb-2b9a-2e2b-80ea-9e3afd9fbfb4@tsoft.com>

```
Yuri <yuri@tsoft.com> writes:

> On 7/26/23 10:29, Junio C Hamano wrote:
>> Are there configuration variables set to affect the behaviour of the
>> "git stash" command in your environment that I do not have (I have
>> nothing in "git config -l | grep stash" output), which may be
>> affecting why it does not reproduce for me?
>
>
> "git config -l | grep stash" doesn't print anything.

Another thing to try.  The command internally uses some internal
form of "git diff" to find out what to save and reset to the HEAD
version in the working tree, so if you have an exotic configuration
variable that affects the way "diff" behaves, it _could_ trigger a
symptom like that (needless to say, the internal invocation of "git
diff" should have prepared for such an end-user configuration and
explicitly countermanded it, but people add configuration variables
after a command was implemented without thinking the ramification
through and especially when they are rarely used ones that do not
usually appear on Git developers' radar, such a bad interaction can
go unnoticed for a long time).

```
