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

Re: Re*: git log --name-only improvement: show old file name in rename

From
NFNathan Faulkner <natedogith1@gmail.com>
Date
May 18, 2024, 00:24 UTC
Message-ID
<02d147ce-78d1-4fd9-b9b4-14b0662188c6@gmail.com>
In-Reply-To
<xmqqv83cl97m.fsf_-_@gitster.g>
On 5/17/2024 12:00 PM, Junio C Hamano wrote:
Show 10 quoted lines
> Nathan Faulkner <natedogith1@gmail.com> writes:
> 
>> The documentation for --name-only says "Show only names of changed
>> files." I would interpret this to mean "output the names of all files
>> that changed", not "output the names of all files that changed, unless
>> git detected it as renamed".
> 
> Interesting observation, but we do show renamed files no?  Even when
> there is no content changes?  A quick experiment tells me it does,
> so "unless" is not quite correct.

It seems to me it's not showing the names of all files. If a file was created and a separate file was deleted, but git happens to detect it as a rename, it will only show the created file even though from my perspective both files changed.

Though even for a true rename, I'd have expected --name-only to show all paths that changed (what you want if you're trying to find code owners or determine what needs to be rebuilt).

Show 14 quoted lines
> diff --git c/Documentation/diff-options.txt w/Documentation/diff-options.txt
> index 0e9456957e..b9eaea32d9 100644
> --- c/Documentation/diff-options.txt
> +++ w/Documentation/diff-options.txt
> @@ -329,7 +329,8 @@ explained for the configuration variable `core.quotePath` (see
>   linkgit:git-config[1]).
>   
>   --name-only::
> -	Show only names of changed files. The file names are often encoded in UTF-8.
> +	Show only the name in the before-tree of changed files.
> +	The file names are often encoded in UTF-8.
>   	For more information see the discussion about encoding in the linkgit:git-log[1]
>   	manual page.
>   

That description sounds to me like it only shows files that existed in the from-commit, not any files that were created in the to-commit.

If the description is updated, it'd probably be a good idea to explicitly call out that --no-renames can be used to get the expected behavior of showing all files that changed.

This behavior can also lead to a situation where git diff --name-only stops reporting a file as changed when including a newer commit that doesn't involve the file.

$ echo '{}' > foo.json; git add .; git commit -m foo $ rm foo.json; git add .; git commit -m delete $ echo '{}' > bar.json; git add .; git commit -m bar

$ git diff --name-only HEAD~2 HEAD~1 foo.json $ git diff --name-only HEAD~1 HEAD bar.json $ git diff --name-only HEAD~2 HEAD bar.json

Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 9 in “git log --name-only improvement: show old file name in rename”
  1. Ed AvisJun 11, 2020
  2. Junio C HamanoJun 11, 2020
  3. Philip OakleyJun 12, 2020
  4. Junio C HamanoJun 12, 2020
  5. Ed AvisJun 15, 2020
  6. Nathan FaulknerMay 16, 2024
  7. Re*: git log --name-only improvement: show old file name in renameJunio C Hamano, May 17, 2024
  8. Nathan FaulknerMay 18, 2024
  9. Junio C HamanoMay 18, 2024

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.