{"thread":{"id":"53657","subject":"git log --name-only improvement: show old file name in rename","startedAt":"2020-06-11T11:19:20Z","lastAt":"2024-05-18T02:05:57Z","messageCount":9,"participants":["Ed Avis","Junio C Hamano","Philip Oakley","Nathan Faulkner"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"399508","messageId":"BL0PR11MB3460BEB60550854661B5178B9D800@BL0PR11MB3460.namprd11.prod.outlook.com","threadId":"53657","inReplyTo":null,"subject":"git log --name-only improvement: show old file name in rename","fromName":"Ed Avis","fromEmail":"ed.avis@qmaw.com","sentAt":"2020-06-11T11:19:14Z","receivedAt":"2020-06-11T11:19:20Z","isPatch":false,"sender":{"key":"ed.avis@qmaw.com","avatar":null},"body":"The git-log manual page says\n\n       --name-only\n           Show only names of changed files.\n\nBut when a file has been renamed, only the new name is printed, not the \nold.  I think it would be more useful and more correct to print both \nnames. \n\nFor example\n\n% git init\nInitialized empty Git repository in /home/eda/test/.git/\n% touch a\n% git add a\n% git commit -mx\n[master (root-commit) ca81aa7] x\n 1 file changed, 0 insertions(+), 0 deletions(-)\n create mode 100644 a\n% git mv a b\n% git commit -my\n[master 7b3925c] y\n 1 file changed, 0 insertions(+), 0 deletions(-)\n rename a => b (100%)\n% git log --name-only -n 1\ncommit 7b3925c1ece26d08d79cf9f06bfcb0b38fea611f (HEAD -> master)\nAuthor: Ed Avis <eda@waniasset.com>\nDate:   2020-06-11 11:59:34 +0100\n\n    y\n\nb\n\n\nI would expect that last log message to show the old filename a as well \nas the new filename b.  If you give --no-renames then both filenames are \nshown, of course, but I think it should be possible to detect the \nrename and print out both old and new names.  There is --name-status \nwhich will print more info including renames, but again I believe \n--name-only should also show both.  Thank you for considering this \nimprovement request.\n\n% git --version\ngit version 2.26.0\n\n-- \nEd Avis <ed.avis@qmaw.com>\n"},{"id":"399569","messageId":"xmqqsgf1i46l.fsf@gitster.c.googlers.com","threadId":"53657","inReplyTo":"BL0PR11MB3460BEB60550854661B5178B9D800@BL0PR11MB3460.namprd11.prod.outlook.com","subject":"Re: git log --name-only improvement: show old file name in rename","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-11T23:16:34Z","receivedAt":"2020-06-11T23:16:39Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ed Avis <ed.avis@qmaw.com> writes:\n\n> The git-log manual page says\n>\n>        --name-only\n>            Show only names of changed files.\n>\n> But when a file has been renamed, only the new name is printed, not the \n> old.  I think it would be more useful and more correct to print both \n> names. \n\nIt is just you who thinks it would be more useful.\n\nScripts written by people over the last 10 years that expect to see\nnew name would certainly hate to see two names start appearing\nthere.\n\nPerhaps you can use --summary at the same time?\n"},{"id":"399589","messageId":"25ca66fb-82bc-7278-90e9-5e1999593068@iee.email","threadId":"53657","inReplyTo":"xmqqsgf1i46l.fsf@gitster.c.googlers.com","subject":"Re: git log --name-only improvement: show old file name in rename","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.email","sentAt":"2020-06-12T14:18:49Z","receivedAt":"2020-06-12T14:18:55Z","isPatch":false,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"@Ed\nOn 12/06/2020 00:16, Junio C Hamano wrote:\n> Ed Avis <ed.avis@qmaw.com> writes:\n>\n>> The git-log manual page says\n>>\n>>        --name-only\n>>            Show only names of changed files.\n>>\n>> But when a file has been renamed, only the new name is printed, not the \n>> old.  I think it would be more useful and more correct to print both \n>> names. \nWas this a concern that the manual did not clarify which name (old or\nnew) was being reported?\nPhilip\n\n> It is just you who thinks it would be more useful.\n>\n> Scripts written by people over the last 10 years that expect to see\n> new name would certainly hate to see two names start appearing\n> there.\n>\n> Perhaps you can use --summary at the same time?\n\n"},{"id":"399609","messageId":"xmqqh7vg2p4p.fsf@gitster.c.googlers.com","threadId":"53657","inReplyTo":"25ca66fb-82bc-7278-90e9-5e1999593068@iee.email","subject":"Re: git log --name-only improvement: show old file name in rename","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-06-12T17:03:02Z","receivedAt":"2020-06-12T17:03:46Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Philip Oakley <philipoakley@iee.email> writes:\n\n> @Ed\n> On 12/06/2020 00:16, Junio C Hamano wrote:\n>> Ed Avis <ed.avis@qmaw.com> writes:\n>>\n>>> The git-log manual page says\n>>>\n>>>        --name-only\n>>>            Show only names of changed files.\n>>>\n>>> But when a file has been renamed, only the new name is printed, not the \n>>> old.  I think it would be more useful and more correct to print both \n>>> names. \n> Was this a concern that the manual did not clarify which name (old or\n> new) was being reported?\n\nGood point.  \n\nI am not Ed so I cannot give an answer to that question, but if we\ndo not document what name is listed in the output, we definitely\nshould.\n\nThanks.\n"},{"id":"399742","messageId":"BL0PR11MB34608AE271344D508676D17A9D9C0@BL0PR11MB3460.namprd11.prod.outlook.com","threadId":"53657","inReplyTo":"xmqqh7vg2p4p.fsf@gitster.c.googlers.com","subject":"Re: git log --name-only improvement: show old file name in rename","fromName":"Ed Avis","fromEmail":"ed.avis@qmaw.com","sentAt":"2020-06-15T07:36:44Z","receivedAt":"2020-06-15T07:36:51Z","isPatch":false,"sender":{"key":"ed.avis@qmaw.com","avatar":null},"body":"Thanks all for your replies to this.  I hoped that --name-only could show when\na filename was removed, as well as when it was added.  If you delete a \nfile in one commit then add it with a new name in the next, both \nfilenames appear in the log.  If these happen in a single commit, only \none does.  And in fact it's not predictable whether you will get one \nfilename or two: it depends on rename detection.  Sometimes if a file is\nchanged and moved to a new name, git log --name-only will show only the\nnew name in the log, but at other times, if git doesn't detect it as a \nrename, both filenames appear.  This feels more like an implementation \ndetail than a deliberate choice.\n\nI accept that scripts may rely on the current behaviour, though I would \nbe surprised to find a script that depended on *not* seeing the old \nfilename printed.\n\nAnyway, if it shouldn't change, or if it cannot change because of backwards compatibility, the manual page could be improved:\n\n           --name-only\n           Show only names of changed or added files.\n           If a file is removed, its name is also printed, unless this is detected\n           as a rename, in which case only the new name is printed.\n\nThat would be enough to direct users towards something more suitable like --compact-summary.\n"},{"id":"494918","messageId":"c239ab15-4d48-4328-8bd5-8e2d77163e03@gmail.com","threadId":"53657","inReplyTo":"BL0PR11MB34608AE271344D508676D17A9D9C0@BL0PR11MB3460.namprd11.prod.outlook.com","subject":"Re: git log --name-only improvement: show old file name in rename","fromName":"Nathan Faulkner","fromEmail":"natedogith1@gmail.com","sentAt":"2024-05-16T23:13:34Z","receivedAt":"2024-05-16T23:13:36Z","isPatch":false,"sender":{"key":"natedogith1@gmail.com","avatar":null},"body":"The documentation for --name-only says \"Show only names of changed \nfiles.\" I would interpret this to mean \"output the names of all files \nthat changed\", not \"output the names of all files that changed, unless \ngit detected it as renamed\".  --no-renames makes it behave as expected, \nbut having to specify it isn't obvious.  A warning in the documentation \ncould help, but --no-renames should probably be included by default when \n--name-only is specified.\n\nI ran into an issue today with code that expected git diff --name-only \nto output all changed files.  A file was created and an unrelated file \nwas deleted in the same commit, but they happened to be similar enough \nthat git detected it as rename, and thus git diff --name-only indicated \nonly one file changed when two files were actually changed.\n\n"},{"id":"494978","messageId":"xmqqv83cl97m.fsf_-_@gitster.g","threadId":"53657","inReplyTo":"c239ab15-4d48-4328-8bd5-8e2d77163e03@gmail.com","subject":"Re*: git log --name-only improvement: show old file name in rename","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-05-17T16:00:29Z","receivedAt":"2024-05-17T16:00:41Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nathan Faulkner <natedogith1@gmail.com> writes:\n\n> The documentation for --name-only says \"Show only names of changed\n> files.\" I would interpret this to mean \"output the names of all files\n> that changed\", not \"output the names of all files that changed, unless\n> git detected it as renamed\".\n\nInteresting observation, but we do show renamed files no?  Even when\nthere is no content changes?  A quick experiment tells me it does,\nso \"unless\" is not quite correct.\n\n    $ git mv COPYING RENAMING\n    $ git diff --name-only -M HEAD\n    RENAMING\n    $ git diff --name-status -M HEAD\n    R100\tCOPYING\tRENAMING\n\nI think that the source of the confusion is actually not renames or\ncopies but that the explanation does not say in which commit the\nphrase \"only names of changed files\" applies to.\n\nThe answer to that question is: Show names of the changed paths in\nthe post-image tree, i.e. if comparing 'diff A B' (or when 'show B'\nis comparing 'diff B^ B'), the names in tree B are shown.\n\nBut because that is not explicitly said, a reader can easily mislead\ninto thinking that we are showing the union of names of files in\nboth pre-image and post-image trees that were modified.\n\nWe'd need something like this, probably.\n\n------- >8 ------------- >8 ------------- >8 -------\nSubject: diff: document what --name-only shows\n\nThe \"--name-only\" option is about showing the name of each file in\nthe post-image tree that got changed and nothing else (like \"was it\ncreated?\").  Unlike the \"--name-status\" option that tells how the\nchange happened (e.g., renamed with similarity), it does not give\nanything else, like the name of the corresponding file in the old\ntree.\n\nLack of the description of this fact has confused readers in the\npast.  Even back when dda2d79a ([PATCH] Clean up diff option\ndescriptions., 2005-07-13) documented \"--name-only\", \"git diff\"\nalready supported the renames, so in a sense, from day one, this\nshould have been documented more clearly but it wasn't.\n\nBelatedly clarify it.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Documentation/diff-options.txt | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git c/Documentation/diff-options.txt w/Documentation/diff-options.txt\nindex 0e9456957e..b9eaea32d9 100644\n--- c/Documentation/diff-options.txt\n+++ w/Documentation/diff-options.txt\n@@ -329,7 +329,8 @@ explained for the configuration variable `core.quotePath` (see\n linkgit:git-config[1]).\n \n --name-only::\n-\tShow only names of changed files. The file names are often encoded in UTF-8.\n+\tShow only the name in the before-tree of changed files.\n+\tThe file names are often encoded in UTF-8.\n \tFor more information see the discussion about encoding in the linkgit:git-log[1]\n \tmanual page.\n \n"},{"id":"495019","messageId":"02d147ce-78d1-4fd9-b9b4-14b0662188c6@gmail.com","threadId":"53657","inReplyTo":"xmqqv83cl97m.fsf_-_@gitster.g","subject":"Re: Re*: git log --name-only improvement: show old file name in rename","fromName":"Nathan Faulkner","fromEmail":"natedogith1@gmail.com","sentAt":"2024-05-18T00:24:20Z","receivedAt":"2024-05-18T00:24:22Z","isPatch":false,"sender":{"key":"natedogith1@gmail.com","avatar":null},"body":"On 5/17/2024 12:00 PM, Junio C Hamano wrote:\n> Nathan Faulkner <natedogith1@gmail.com> writes:\n> \n>> The documentation for --name-only says \"Show only names of changed\n>> files.\" I would interpret this to mean \"output the names of all files\n>> that changed\", not \"output the names of all files that changed, unless\n>> git detected it as renamed\".\n> \n> Interesting observation, but we do show renamed files no?  Even when\n> there is no content changes?  A quick experiment tells me it does,\n> so \"unless\" is not quite correct.\n\nIt seems to me it's not showing the names of all files.  If a file was \ncreated and a separate file was deleted, but git happens to detect it as \na rename, it will only show the created file even though from my \nperspective both files changed.\n\nThough even for a true rename, I'd have expected --name-only to show all \npaths that changed (what you want if you're trying to find code owners \nor determine what needs to be rebuilt).\n\n> diff --git c/Documentation/diff-options.txt w/Documentation/diff-options.txt\n> index 0e9456957e..b9eaea32d9 100644\n> --- c/Documentation/diff-options.txt\n> +++ w/Documentation/diff-options.txt\n> @@ -329,7 +329,8 @@ explained for the configuration variable `core.quotePath` (see\n>   linkgit:git-config[1]).\n>   \n>   --name-only::\n> -\tShow only names of changed files. The file names are often encoded in UTF-8.\n> +\tShow only the name in the before-tree of changed files.\n> +\tThe file names are often encoded in UTF-8.\n>   \tFor more information see the discussion about encoding in the linkgit:git-log[1]\n>   \tmanual page.\n>   \n\nThat description sounds to me like it only shows files that existed in \nthe from-commit, not any files that were created in the to-commit.\n\nIf the description is updated, it'd probably be a good idea to \nexplicitly call out that --no-renames can be used to get the expected \nbehavior of showing all files that changed.\n\n\nThis behavior can also lead to a situation where git diff --name-only \nstops reporting a file as changed when including a newer commit that \ndoesn't involve the file.\n\n$ echo '{}' > foo.json; git add .; git commit -m foo\n$ rm foo.json; git add .; git commit -m delete\n$ echo '{}' > bar.json; git add .; git commit -m bar\n\n$ git diff --name-only HEAD~2 HEAD~1\nfoo.json\n$ git diff --name-only HEAD~1 HEAD\nbar.json\n$ git diff --name-only HEAD~2 HEAD\nbar.json\n\n"},{"id":"495023","messageId":"xmqqo793dgcd.fsf@gitster.g","threadId":"53657","inReplyTo":"02d147ce-78d1-4fd9-b9b4-14b0662188c6@gmail.com","subject":"Re: Re*: git log --name-only improvement: show old file name in rename","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-05-18T02:05:54Z","receivedAt":"2024-05-18T02:05:57Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nathan Faulkner <natedogith1@gmail.com> writes:\n\n> That description sounds to me like it only shows files that existed in\n> the from-commit, not any files that were created in the to-commit.\n\nSorry, this was a typo/thinko.  An updated version was posted on the\nlist after the message you are responding to.\n"}]}