# `git diff` after `git checkout from-branch -- files` reports nothing

3 messages from 2021-11-30 to 2021-11-30. Participants: Noel Yap, Bryan Turner.
Thread: https://gitlist.dev/t/57004

## Noel Yap, 2021-11-30 20:48

Subject: `git diff` after `git checkout from-branch -- files` reports nothing
Message-ID: <CALa_nQ=Q1h9b_BZcg9AeJurLeRpGrpUFuyoMz-DYKB3bgFJj4Q@mail.gmail.com>
URL: https://gitlist.dev/e/CALa_nQ%3DQ1h9b_BZcg9AeJurLeRpGrpUFuyoMz-DYKB3bgFJj4Q%40mail.gmail.com

```
Thank you for filling out a Git bug report!
Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue)

`git checkout -b to-branch; git checkout from-branch -- filenames; git
status; git diff`

What did you expect to happen? (Expected behavior)

`git status` expected to show updated files and `git diff` expected to
show file changes.

What happened instead? (Actual behavior)

`git status` showed updated files but `git diff` showed no file changes.

What's different between what you expected and what actually happened?

`git diff` was expected to show file changes but it showed nothing instead.

Anything else you want to add:

If I `git reset -q HEAD -- filenames`, `git diff` starts showing file changes.

Please review the rest of the bug report below.
You can delete any lines you don't wish to share.


[System Info]
git version:
git version 2.34.1
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
uname: Linux 5.11.0-36-generic #40~20.04.1-Ubuntu SMP Sat Sep 18
02:14:19 UTC 2021 x86_64
compiler info: gnuc: 9.3
libc info: glibc: 2.31
$SHELL (typically, interactive shell): /bin/bash


[Enabled Hooks]
applypatch-msg
commit-msg
post-applypatch
post-checkout
post-commit
post-merge
post-receive
post-rewrite
post-update
pre-applypatch
pre-auto-gc
pre-commit
pre-merge-commit
pre-push
pre-rebase
pre-receive
prepare-commit-msg
push-to-checkout
sendemail-validate
update

```

## Bryan Turner, 2021-11-30 21:39

Subject: Re: `git diff` after `git checkout from-branch -- files` reports nothing
Message-ID: <CAGyf7-Ea719UNEAQSTeeSYyCcsqMo5TWXR+dSr8sDqDfj+tLAA@mail.gmail.com>
URL: https://gitlist.dev/e/CAGyf7-Ea719UNEAQSTeeSYyCcsqMo5TWXR%2BdSr8sDqDfj%2BtLAA%40mail.gmail.com
In-Reply-To: <CALa_nQ=Q1h9b_BZcg9AeJurLeRpGrpUFuyoMz-DYKB3bgFJj4Q@mail.gmail.com>

```
On Tue, Nov 30, 2021 at 12:49 PM Noel Yap <noel.yap@gmail.com> wrote:
>
> Thank you for filling out a Git bug report!
> Please answer the following questions to help us understand your issue.
>
> What did you do before the bug happened? (Steps to reproduce your issue)
>
> `git checkout -b to-branch; git checkout from-branch -- filenames; git
> status; git diff`

"git diff" as run here by default only shows _unstaged_ changes. Since
you ran "git checkout from-branch -- filenames", those changes were
_staged_. That means you'd need "git diff --cached" or "git diff
--staged" to see them.
>
> What did you expect to happen? (Expected behavior)
>
> `git status` expected to show updated files and `git diff` expected to
> show file changes.
>
> What happened instead? (Actual behavior)
>
> `git status` showed updated files but `git diff` showed no file changes.

"git status" compares the working copy to the index, so it will always
show the changes, but it has 2 different blocks, staged and unstaged
changes. If your changes appear in the staged block, you need "git
diff --cached" or "git diff --staged". If they're in the unstaged
block, they'll be visible in "git diff".

>
> What's different between what you expected and what actually happened?
>
> `git diff` was expected to show file changes but it showed nothing instead.
>
> Anything else you want to add:
>
> If I `git reset -q HEAD -- filenames`, `git diff` starts showing file changes.

This unstaged the changes, at which point they show in a plain "git
diff". They also would move from the staged block to the unstaged
block in your "git status" output.

As far as I can tell everything is working as intended.

Hope this helps,
Bryan Turner

>
> Please review the rest of the bug report below.
> You can delete any lines you don't wish to share.
>
>
> [System Info]
> git version:
> git version 2.34.1
> cpu: x86_64
> no commit associated with this build
> sizeof-long: 8
> sizeof-size_t: 8
> shell-path: /bin/sh
> uname: Linux 5.11.0-36-generic #40~20.04.1-Ubuntu SMP Sat Sep 18
> 02:14:19 UTC 2021 x86_64
> compiler info: gnuc: 9.3
> libc info: glibc: 2.31
> $SHELL (typically, interactive shell): /bin/bash
>
>
> [Enabled Hooks]
> applypatch-msg
> commit-msg
> post-applypatch
> post-checkout
> post-commit
> post-merge
> post-receive
> post-rewrite
> post-update
> pre-applypatch
> pre-auto-gc
> pre-commit
> pre-merge-commit
> pre-push
> pre-rebase
> pre-receive
> prepare-commit-msg
> push-to-checkout
> sendemail-validate
> update

```

## Noel Yap, 2021-11-30 23:34

Subject: Re: `git diff` after `git checkout from-branch -- files` reports nothing
Message-ID: <CALa_nQmTeE9fDFN_=F4YwY-A=BQRpB_twh-X3Fw1ks=8UGNs9g@mail.gmail.com>
URL: https://gitlist.dev/e/CALa_nQmTeE9fDFN_%3DF4YwY-A%3DBQRpB_twh-X3Fw1ks%3D8UGNs9g%40mail.gmail.com
In-Reply-To: <CAGyf7-Ea719UNEAQSTeeSYyCcsqMo5TWXR+dSr8sDqDfj+tLAA@mail.gmail.com>

```
I didn't know this about `git diff`. Thanks for the info!

On Tue, Nov 30, 2021 at 1:39 PM Bryan Turner <bturner@atlassian.com> wrote:
>
> On Tue, Nov 30, 2021 at 12:49 PM Noel Yap <noel.yap@gmail.com> wrote:
> >
> > Thank you for filling out a Git bug report!
> > Please answer the following questions to help us understand your issue.
> >
> > What did you do before the bug happened? (Steps to reproduce your issue)
> >
> > `git checkout -b to-branch; git checkout from-branch -- filenames; git
> > status; git diff`
>
> "git diff" as run here by default only shows _unstaged_ changes. Since
> you ran "git checkout from-branch -- filenames", those changes were
> _staged_. That means you'd need "git diff --cached" or "git diff
> --staged" to see them.
> >
> > What did you expect to happen? (Expected behavior)
> >
> > `git status` expected to show updated files and `git diff` expected to
> > show file changes.
> >
> > What happened instead? (Actual behavior)
> >
> > `git status` showed updated files but `git diff` showed no file changes.
>
> "git status" compares the working copy to the index, so it will always
> show the changes, but it has 2 different blocks, staged and unstaged
> changes. If your changes appear in the staged block, you need "git
> diff --cached" or "git diff --staged". If they're in the unstaged
> block, they'll be visible in "git diff".
>
> >
> > What's different between what you expected and what actually happened?
> >
> > `git diff` was expected to show file changes but it showed nothing instead.
> >
> > Anything else you want to add:
> >
> > If I `git reset -q HEAD -- filenames`, `git diff` starts showing file changes.
>
> This unstaged the changes, at which point they show in a plain "git
> diff". They also would move from the staged block to the unstaged
> block in your "git status" output.
>
> As far as I can tell everything is working as intended.
>
> Hope this helps,
> Bryan Turner
>
> >
> > Please review the rest of the bug report below.
> > You can delete any lines you don't wish to share.
> >
> >
> > [System Info]
> > git version:
> > git version 2.34.1
> > cpu: x86_64
> > no commit associated with this build
> > sizeof-long: 8
> > sizeof-size_t: 8
> > shell-path: /bin/sh
> > uname: Linux 5.11.0-36-generic #40~20.04.1-Ubuntu SMP Sat Sep 18
> > 02:14:19 UTC 2021 x86_64
> > compiler info: gnuc: 9.3
> > libc info: glibc: 2.31
> > $SHELL (typically, interactive shell): /bin/bash
> >
> >
> > [Enabled Hooks]
> > applypatch-msg
> > commit-msg
> > post-applypatch
> > post-checkout
> > post-commit
> > post-merge
> > post-receive
> > post-rewrite
> > post-update
> > pre-applypatch
> > pre-auto-gc
> > pre-commit
> > pre-merge-commit
> > pre-push
> > pre-rebase
> > pre-receive
> > prepare-commit-msg
> > push-to-checkout
> > sendemail-validate
> > update

```
