From: Ben Knoble <ben.knoble@gmail•com>
To: Harrison McCullough <mccullough.harrison@gmail•com>
Cc: git@vger•kernel.org
Subject: Re: Unexpected behavior in git diff --relative=<path>
Date: Tue, 6 Jan 2026 11:58:09 -0500 [thread overview]
Message-ID: <8113ACE3-288F-46D5-949F-CEDF3D9D0E25@gmail.com> (raw)
In-Reply-To: <CAHLeu+ww7bBACO97ddkHeL2nkwmwqNL9G2Bjq18NZr5_d-MHyQ@mail.gmail.com>
> Le 5 janv. 2026 à 17:56, Harrison McCullough <mccullough.harrison@gmail•com> a écrit :
>
> What did you do before the bug happened? (Steps to reproduce your issue)
>
> - Create a "foo.txt" file
> - Commit the "foo.txt"
> - Modify the "foo.txt" file
> - Create a "foo/bar.txt" file
> - Commit the "foo/bar.txt"
> - Modify the "foo/bar.txt" file
> - Run `git diff --name-only --relative=foo`
>
>
> What did you expect to happen? (Expected behavior)
>
> I would expect to only see modified files inside the "foo/" directory. For
> example, I would expect this to be the output:
>
> ```
> $ git diff --name-only --relative=foo
> bar.txt
> ```
>
>
> What happened instead? (Actual behavior)
>
> Both the "foo/bar.txt" _and_ the "foo.txt" files were listed--but the "foo.txt"
> file had the "foo" prefix stripped, appearing as just ".txt".
>
> ```
> $ git diff --name-only --relative=foo
> .txt
> bar.txt
> ```
Easy to reproduce (with f or fo, too).
> What's different between what you expected and what actually happened?
>
> Using the `--relative=<path>` flag to `git diff` appears to simply remove the
> prefix from each file, regardless of whether that is a full path prefix or just
> part of the file name.
>
>
> Anything else you want to add:
>
> This is the relevant part of the man page for `git-diff`:
>
>> When run from a subdirectory of the project, it can be told to exclude changes
>> outside the directory and show pathnames relative to it with this option. When
>> you are not in a subdirectory (e.g. in a bare repository), you can name which
>> subdirectory to make the output relative to by giving a <path> as an argument.
>> --no-relative can be used to countermand both diff.relative config option and
>> previous --relative.
The wording implies to me that “=<path>” is only intended for use with bare repositories. With working trees, use just the relative option from within a directory:
(cd foo && git diff - -relative)
If that’s right (?), then the docs should probably be more direct about the way each is intended to be used. I can imagine some use cases for the stripping behavior in non-bare repos, but mostly around ad-hoc scripts.
prev parent reply other threads:[~2026-01-06 16:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-05 22:56 Unexpected behavior in git diff --relative=<path> Harrison McCullough
2026-01-06 16:58 ` Ben Knoble [this message]
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=8113ACE3-288F-46D5-949F-CEDF3D9D0E25@gmail.com \
--to=ben.knoble@gmail$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=mccullough.harrison@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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