{"thread":{"id":"58033","subject":"git a/xyz or b/xyz","startedAt":"2022-06-18T10:45:40Z","lastAt":"2022-06-24T15:59:04Z","messageCount":5,"participants":["Fabrice Creuzot","Shaoxuan Yuan","Konstantin Khomoutov"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"457492","messageId":"b4f40821-8592-1a35-8b60-219fd7e29e9f@luigifab.fr","threadId":"58033","inReplyTo":null,"subject":"git a/xyz or b/xyz","fromName":"Fabrice Creuzot","fromEmail":"code@luigifab.fr","sentAt":"2022-06-18T10:45:30Z","receivedAt":"2022-06-18T10:45:40Z","isPatch":false,"sender":{"key":"code@luigifab.fr","avatar":null},"body":"Hello\n\nWhen we are reading a \"git diff\", all paths are prefixed with \"a/\" and \n\"b/\". Example:\n\ndiff --git a/xyz\nindex 4aa4b5230..1c2b8b69e 100644\n--- a/xyz\n+++ b/xyz\n@@ -1,7 +1,7 @@\n\n\nWith my terminal, I double click on the path to select the full path for \ncopy.\n\nThen, when I paste: \"git log a/xyz\",\n  git says: unknown revision or path not in the working tree\n\nOk, I need to remove the \"a/\" or \"b/\".\nBut, is git can understand that \"a/xyz\" is \"xyz\" because \"a/xyz\" does \nnot exist?\n\nThanks\n"},{"id":"457495","messageId":"CAJyCBORdr3kaBbBmec5T5JAjcUpq6mSKQC=8_poLaZzSpkMJLA@mail.gmail.com","threadId":"58033","inReplyTo":"b4f40821-8592-1a35-8b60-219fd7e29e9f@luigifab.fr","subject":"Re: git a/xyz or b/xyz","fromName":"Shaoxuan Yuan","fromEmail":"shaoxuan.yuan02@gmail.com","sentAt":"2022-06-18T11:09:55Z","receivedAt":"2022-06-18T11:10:58Z","isPatch":false,"sender":{"key":"shaoxuan.yuan02@gmail.com","avatar":"https://avatars.githubusercontent.com/u/46557895?v=4"},"body":"On Sat, Jun 18, 2022 at 6:50 PM Fabrice Creuzot <code@luigifab.fr> wrote:\n>\n> Hello\n>\n> When we are reading a \"git diff\", all paths are prefixed with \"a/\" and\n> \"b/\". Example:\n> diff --git a/xyz\n> index 4aa4b5230..1c2b8b69e 100644\n> --- a/xyz\n> +++ b/xyz\n> @@ -1,7 +1,7 @@\n>\n>\n> With my terminal, I double click on the path to select the full path for\n> copy.\n>\n> Then, when I paste: \"git log a/xyz\",\n>   git says: unknown revision or path not in the working tree\n>\n> Ok, I need to remove the \"a/\" or \"b/\".\n> But, is git can understand that \"a/xyz\" is \"xyz\" because \"a/xyz\" does\n> not exist?\n>\n> Thanks\n\nHi Fabrice,\n\nYou can think that \"a/\" stands for \"before\" or \"old content\", whereas\n \"b/\" stands for \"after\" or \"new content\". Paths are prefixed with these\nto indicate which is before and which is after.\n\nFor example, when you call \"git diff\", it is to \"view the changes you made\nrelative to the index (staging area for the next commit)\".\nIn this case, \"before\" is the index, namely \"a/\", whereas \"after\"\nis your current working tree, namely \"b/\".\n\n-- \nThanks & Regards,\nShaoxuan\n"},{"id":"457499","messageId":"CAJyCBOSc_n0is=77Ua_VZbce81qA0yKbUm6Dp2TxxpFAgVQ1OA@mail.gmail.com","threadId":"58033","inReplyTo":"CAJyCBORdr3kaBbBmec5T5JAjcUpq6mSKQC=8_poLaZzSpkMJLA@mail.gmail.com","subject":"Re: git a/xyz or b/xyz","fromName":"Shaoxuan Yuan","fromEmail":"shaoxuan.yuan02@gmail.com","sentAt":"2022-06-18T11:15:01Z","receivedAt":"2022-06-18T11:15:17Z","isPatch":false,"sender":{"key":"shaoxuan.yuan02@gmail.com","avatar":"https://avatars.githubusercontent.com/u/46557895?v=4"},"body":"On Sat, Jun 18, 2022 at 7:09 PM Shaoxuan Yuan <shaoxuan.yuan02@gmail.com> wrote:\n>\n> On Sat, Jun 18, 2022 at 6:50 PM Fabrice Creuzot <code@luigifab.fr> wrote:\n> >\n> > Hello\n> >\n> > When we are reading a \"git diff\", all paths are prefixed with \"a/\" and\n> > \"b/\". Example:\n> > diff --git a/xyz\n> > index 4aa4b5230..1c2b8b69e 100644\n> > --- a/xyz\n> > +++ b/xyz\n> > @@ -1,7 +1,7 @@\n> >\n> >\n> > With my terminal, I double click on the path to select the full path for\n> > copy.\n> >\n> > Then, when I paste: \"git log a/xyz\",\n> >   git says: unknown revision or path not in the working tree\n> >\n> > Ok, I need to remove the \"a/\" or \"b/\".\n> > But, is git can understand that \"a/xyz\" is \"xyz\" because \"a/xyz\" does\n> > not exist?\n> >\n> > Thanks\n>\n> Hi Fabrice,\n>\n> You can think that \"a/\" stands for \"before\" or \"old content\", whereas\n>  \"b/\" stands for \"after\" or \"new content\". Paths are prefixed with these\n> to indicate which is before and which is after.\n>\n> For example, when you call \"git diff\", it is to \"view the changes you made\n> relative to the index (staging area for the next commit)\".\n> In this case, \"before\" is the index, namely \"a/\", whereas \"after\"\n> is your current working tree, namely \"b/\".\n\nA more precise way of saying is \"a/\" stands for source, whereas \"b/\"\nstands for destination.\n\n-- \nThanks & Regards,\nShaoxuan\n"},{"id":"457548","messageId":"20220620111230.ck7nkouzkviidtcu@carbon","threadId":"58033","inReplyTo":"b4f40821-8592-1a35-8b60-219fd7e29e9f@luigifab.fr","subject":"Re: git a/xyz or b/xyz","fromName":"Konstantin Khomoutov","fromEmail":"kostix@bswap.ru","sentAt":"2022-06-20T11:12:30Z","receivedAt":"2022-06-20T11:14:55Z","isPatch":false,"sender":{"key":"kostix@bswap.ru","avatar":null},"body":"On Sat, Jun 18, 2022 at 12:45:30PM +0200, Fabrice Creuzot wrote:\n\n> When we are reading a \"git diff\", all paths are prefixed with \"a/\" and \"b/\".\n> Example:\n> \n> diff --git a/xyz\n> index 4aa4b5230..1c2b8b69e 100644\n> --- a/xyz\n> +++ b/xyz\n> @@ -1,7 +1,7 @@\n> \n> \n> With my terminal, I double click on the path to select the full path for\n> copy.\n> \n> Then, when I paste: \"git log a/xyz\",\n>  git says: unknown revision or path not in the working tree\n> \n> Ok, I need to remove the \"a/\" or \"b/\".\n> But, is git can understand that \"a/xyz\" is \"xyz\" because \"a/xyz\" does not\n> exist?\n\nA quick answer: pass `git diff` the \"--no-prefix\" command-line option to\nsuppress generation of these prefixes.\n\n\nA bit of historical context.\n\nPlease note that `git diff` - at least by default - generates its output using\nthe format known as \"unified diff\" which was invented an implemented way\nbefore Git was concieved [1]. Quite probably on your system you have access to\nthe two command line tools - `diff` and `patch`, - one of which generates\ndiffs by comparing two files, and another one being able to update a file\nusing a patch information produced by the former.\n\nThe diff format records the pathnames of the files compared when the patch\ndata was generated.\n\nNow consider that a patch file can describe changes to apply to any set of\nfiles. In order to achieve this, the format has to name the files to be used.\n\nNow consider that the diff format can use used for two conceptually slightly\ndifferent purposes:\n\n - A patch file in this format can describe a set of \"concrete\" changes.\n\n   Say, you pass a patch file to someone, they just run `patch` on it and\n   that tool patches a set of files no matter where it was run from.\n\n - A patch file in this format can describe a set of changes intended to\n   be applied to a particular state of a file or a set of files, possibly\n   comprising a hierarchy, located anywhere in the target filesystem.\n   \n   A good example is a source tree of a software project: a user can fetch\n   a tarball with a software project and unpack it everywhere they wish.\n   They then should be able to apply a patch file to that unpacked tree.\n\nNote that in the former case the names of the names of the files listed in a\npatch file may not share even the smallest common prefix while in the second\ncase they will have the same prefix, and the prefix may not even be needed at\nall.\n\nHistorically the patch files to be used in the second case were generated by\nrunning a tool like `diff` against the two hierarchies of files: a source,\nunmodified directory, and the copy of that directly with the necessary\nmodifications. That is, you'd run something like\n\n  $ diff -u srcdir modified > changes.patch\n\nand because of that the generated patch file would naturally contain file\nnames starting with \"srcdir/\" and \"modified/\" prefixes.\n\nThe tool to apply patch files, `patch`, has a command-line option \"-p\" (for\n\"prefix\") which can be used to strip the specified number of prefix\ndirectories from the names of the files when applying a patch file. So to\napply a patch generated by comparing two directory hierarchy you'd routinely\npass \"-p1\" to that tool, like in\n\n  $ cd srcdir\n  $ patch -p1 < changes.patch\n\n\nOK, so you can now note that `git diff` is different from the classical patch\nmaniputation tools in that its operation is somewhat virtualized: by default\nit generates a patch describing the set of differences between the work tree\nand the index, and can be told to generate a patch between sets of files in\nnamed revisions and so on. So there's no two directories physically existing\non the file system and so `git diff` generates fake prefixes.\n\nExactly why it does so by default, I don't know, but I suppose it's just to be\nin line with the classical use case explained above which was in widespread\nuse before Git even existed.\n\n1. https://en.wikipedia.org/wiki/Diff#Unified_format\n\n"},{"id":"457853","messageId":"7c490fea-fa8a-0245-5b3f-981b8797a7cd@luigifab.fr","threadId":"58033","inReplyTo":"20220620111230.ck7nkouzkviidtcu@carbon","subject":"Re: git a/xyz or b/xyz","fromName":"Fabrice Creuzot","fromEmail":"code@luigifab.fr","sentAt":"2022-06-24T15:58:56Z","receivedAt":"2022-06-24T15:59:04Z","isPatch":false,"sender":{"key":"code@luigifab.fr","avatar":null},"body":"Thanks! --no-prefix do the job.\n\nLe 20/06/2022 à 13:12, Konstantin Khomoutov a écrit :\n> On Sat, Jun 18, 2022 at 12:45:30PM +0200, Fabrice Creuzot wrote:\n> \n>> When we are reading a \"git diff\", all paths are prefixed with \"a/\" and \"b/\".\n>> Example:\n>>\n>> diff --git a/xyz\n>> index 4aa4b5230..1c2b8b69e 100644\n>> --- a/xyz\n>> +++ b/xyz\n>> @@ -1,7 +1,7 @@\n>>\n>>\n>> With my terminal, I double click on the path to select the full path for\n>> copy.\n>>\n>> Then, when I paste: \"git log a/xyz\",\n>>   git says: unknown revision or path not in the working tree\n>>\n>> Ok, I need to remove the \"a/\" or \"b/\".\n>> But, is git can understand that \"a/xyz\" is \"xyz\" because \"a/xyz\" does not\n>> exist?\n> \n> A quick answer: pass `git diff` the \"--no-prefix\" command-line option to\n> suppress generation of these prefixes.\n> \n> \n> A bit of historical context.\n> \n> Please note that `git diff` - at least by default - generates its output using\n> the format known as \"unified diff\" which was invented an implemented way\n> before Git was concieved [1]. Quite probably on your system you have access to\n> the two command line tools - `diff` and `patch`, - one of which generates\n> diffs by comparing two files, and another one being able to update a file\n> using a patch information produced by the former.\n> \n> The diff format records the pathnames of the files compared when the patch\n> data was generated.\n> \n> Now consider that a patch file can describe changes to apply to any set of\n> files. In order to achieve this, the format has to name the files to be used.\n> \n> Now consider that the diff format can use used for two conceptually slightly\n> different purposes:\n> \n>   - A patch file in this format can describe a set of \"concrete\" changes.\n> \n>     Say, you pass a patch file to someone, they just run `patch` on it and\n>     that tool patches a set of files no matter where it was run from.\n> \n>   - A patch file in this format can describe a set of changes intended to\n>     be applied to a particular state of a file or a set of files, possibly\n>     comprising a hierarchy, located anywhere in the target filesystem.\n>     \n>     A good example is a source tree of a software project: a user can fetch\n>     a tarball with a software project and unpack it everywhere they wish.\n>     They then should be able to apply a patch file to that unpacked tree.\n> \n> Note that in the former case the names of the names of the files listed in a\n> patch file may not share even the smallest common prefix while in the second\n> case they will have the same prefix, and the prefix may not even be needed at\n> all.\n> \n> Historically the patch files to be used in the second case were generated by\n> running a tool like `diff` against the two hierarchies of files: a source,\n> unmodified directory, and the copy of that directly with the necessary\n> modifications. That is, you'd run something like\n> \n>    $ diff -u srcdir modified > changes.patch\n> \n> and because of that the generated patch file would naturally contain file\n> names starting with \"srcdir/\" and \"modified/\" prefixes.\n> \n> The tool to apply patch files, `patch`, has a command-line option \"-p\" (for\n> \"prefix\") which can be used to strip the specified number of prefix\n> directories from the names of the files when applying a patch file. So to\n> apply a patch generated by comparing two directory hierarchy you'd routinely\n> pass \"-p1\" to that tool, like in\n> \n>    $ cd srcdir\n>    $ patch -p1 < changes.patch\n> \n> \n> OK, so you can now note that `git diff` is different from the classical patch\n> maniputation tools in that its operation is somewhat virtualized: by default\n> it generates a patch describing the set of differences between the work tree\n> and the index, and can be told to generate a patch between sets of files in\n> named revisions and so on. So there's no two directories physically existing\n> on the file system and so `git diff` generates fake prefixes.\n> \n> Exactly why it does so by default, I don't know, but I suppose it's just to be\n> in line with the classical use case explained above which was in widespread\n> use before Git even existed.\n> \n> 1. https://en.wikipedia.org/wiki/Diff#Unified_format\n> \n"}]}