git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Unexpected behavior in git diff --relative=<path>

From
Ben Knoble <ben.knoble@gmail.com>
Date
Jan 6, 2026, 16:58 UTC
Message-ID
<8113ACE3-288F-46D5-949F-CEDF3D9D0E25@gmail.com>
In-Reply-To
<CAHLeu+ww7bBACO97ddkHeL2nkwmwqNL9G2Bjq18NZr5_d-MHyQ@mail.gmail.com>
Show 34 quoted lines
> 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).
Show 17 quoted lines
> 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. 
Previous: Harrison McCullough
Message 2 of 2 in “Unexpected behavior in git diff --relative=<path>”
  1. Harrison McCulloughJan 5, 2026
  2. Ben KnobleJan 6, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.