{"thread":{"id":"58701","subject":"Git add documentation error","startedAt":"2022-10-27T11:53:24Z","lastAt":"2022-10-27T19:15:49Z","messageCount":8,"participants":["Angelo Borsotti","Philip Oakley","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"465866","messageId":"CAB9Jk9Ay2PPEYKve3DXVmG__yZjO1mgh1MxaKA+wfsF0ZvKRqA@mail.gmail.com","threadId":"58701","inReplyTo":null,"subject":"Git add documentation error","fromName":"Angelo Borsotti","fromEmail":"angelo.borsotti@gmail.com","sentAt":"2022-10-27T11:53:09Z","receivedAt":"2022-10-27T11:53:24Z","isPatch":false,"sender":{"key":"angelo.borsotti@gmail.com","avatar":null},"body":"Hello,\n\nthe reference manual for the \"git add\" command does not\nspecify what that command does when applied to an\nunmodified file.\nBy testing this, I have seen that it does not add the file\nto the index, and consequently it does not add it when a\nsubsequent commit is done.\nI think that this should be documented.\n\nThank you\n-Angelo Borsotti\n"},{"id":"465869","messageId":"b0008377-2cb5-72ff-e94b-8182065b3436@iee.email","threadId":"58701","inReplyTo":"CAB9Jk9Ay2PPEYKve3DXVmG__yZjO1mgh1MxaKA+wfsF0ZvKRqA@mail.gmail.com","subject":"Re: Git add documentation error","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.email","sentAt":"2022-10-27T15:10:48Z","receivedAt":"2022-10-27T15:15:09Z","isPatch":false,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"Hi,\nOn 27/10/2022 12:53, Angelo Borsotti wrote:\n> Hello,\n>\n> the reference manual for the \"git add\" command does not\n> specify what that command does when applied to an\n> unmodified file.\n\nI presume that this file is already tracked..\n> By testing this, I have seen that it does not add the file\n> to the index, \n\nHow was this tested?\n\nIf you have no changes, thaen the status diff will have no mention of\nthat file.\nPerhaps change the tracked mode bits to see if that is noticed (note\nthough, not all mode bits are tracked..)\n> and consequently it does not add it when a\n> subsequent commit is done.\n\nI suspect this is a subtle mental model misunderstanding about the\ndistinction between a commit as a snapshot, and a commit being reported\nas the diff relative to its parent (and here, there is none, if the file\nis unmodified)\n> I think that this should be documented.\n\nA test script with sample output would help here.\n--\nPhilip\n\n\n"},{"id":"465870","messageId":"2ed22fa1-4d9d-e50a-18cf-048007272729@iee.email","threadId":"58701","inReplyTo":"CAB9Jk9BBddd5d0wKFB0eJw1OMMAQj88J9Bn1Yn1rbK_F1mEs1A@mail.gmail.com","subject":"Re: Git add documentation error","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.email","sentAt":"2022-10-27T16:16:03Z","receivedAt":"2022-10-27T16:17:13Z","isPatch":false,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"Hi Angelo, please use 'reply all' so others can participate.\nAlso, in-line replies are preferred.\n\nOn 27/10/2022 16:28, Angelo Borsotti wrote:\n> Hi,\n>\n> I have tested this in the following way: I have two files: C1.java and C2.java\n>\n>     > git status\n>     On branch master\n>     nothing added to commit\n>     > ... edit C2.java\n>     > git status\n>     On branch master\n>     Changes not staged for commit:\n>     (use \"git add <file>...\" to update what will be committed)\n>     (use \"git restore <file>...\" to discard changes in working directory)\n>         modified:   C2.java\n>      > git add C1.java\n>      > git add C2.java\n>      > git commit -m \"commit2\"\n>      D:\\gittest>git commit -m \"commit1\"\n>      [master 91ef45d] commit1\n>      1 file changed, 1 insertion(+), 1 deletion(-)\n>\n> In commit1 there is only one file, which is C2.java.\n\nIt does say \"1 file changed\", which is true.\nWhat it fails to mention is all the other files that are included within\nthe commit, but are unchanged.\n\nMaybe have a look at\nhttps://git-scm.com/docs/git-ls-tree#Documentation/git-ls-tree.txt---name-status,\nprobably with the -r option (check the command's description)\n\nWhat Git version & OS are you on?\n> This is a useful feature: one can stage all its files without\n> bothering to remember\n> which one had been changed, and then make a commit, and place the commands\n> to do it in a script to be used each time a new commit is needed.\n>\n> -Angelo\n>     ...\n>\n> On Thu, 27 Oct 2022 at 17:10, Philip Oakley <philipoakley@iee.email> wrote:\n>> Hi,\n>> On 27/10/2022 12:53, Angelo Borsotti wrote:\n>>> Hello,\n>>>\n>>> the reference manual for the \"git add\" command does not\n>>> specify what that command does when applied to an\n>>> unmodified file.\n>> I presume that this file is already tracked..\n>>> By testing this, I have seen that it does not add the file\n>>> to the index,\n>> How was this tested?\n>>\n>> If you have no changes, thaen the status diff will have no mention of\n>> that file.\n>> Perhaps change the tracked mode bits to see if that is noticed (note\n>> though, not all mode bits are tracked..)\n>>> and consequently it does not add it when a\n>>> subsequent commit is done.\n>> I suspect this is a subtle mental model misunderstanding about the\n>> distinction between a commit as a snapshot, and a commit being reported\n>> as the diff relative to its parent (and here, there is none, if the file\n>> is unmodified)\n>>> I think that this should be documented.\n>> A test script with sample output would help here.\n>> --\n>> Philip\n>>\n>>\n\n"},{"id":"465880","messageId":"CAB9Jk9DPdVmmb2DPDKPm5FLGr-XJa5kNouCYmcjh534Y2z1rVQ@mail.gmail.com","threadId":"58701","inReplyTo":"2ed22fa1-4d9d-e50a-18cf-048007272729@iee.email","subject":"Re: Git add documentation error","fromName":"Angelo Borsotti","fromEmail":"angelo.borsotti@gmail.com","sentAt":"2022-10-27T16:57:21Z","receivedAt":"2022-10-27T16:57:39Z","isPatch":false,"sender":{"key":"angelo.borsotti@gmail.com","avatar":null},"body":"Hi Philip.\n\nI have git 2.38.0.windows.1 on  windows 10.\n\nI have then changed again C2.java, and made only one git add, and a commit\n\n     > git add C2.java\n     > git commit -m \"commit2\"\n     [master 8ec0c2f] commit2\n     1 file changed, 1 insertion(+), 1 deletion(-)\n\nThen I displayed the contents of both commits, and seen that it is pretty much\nthe same:\n\nD:\\gittest>git show --pretty=\"\" --name-only 91ef45d\nC2.java\n\nD:\\gittest>git show --pretty=\"\" --name-only 8ec0c2f\nC2.java\n\nIf there is any difference in the files, probably it is under the hood.\n\n-Angelo\n\nOn Thu, 27 Oct 2022 at 18:16, Philip Oakley <philipoakley@iee.email> wrote:\n>\n> Hi Angelo, please use 'reply all' so others can participate.\n> Also, in-line replies are preferred.\n>\n> On 27/10/2022 16:28, Angelo Borsotti wrote:\n> > Hi,\n> >\n> > I have tested this in the following way: I have two files: C1.java and C2.java\n> >\n> >     > git status\n> >     On branch master\n> >     nothing added to commit\n> >     > ... edit C2.java\n> >     > git status\n> >     On branch master\n> >     Changes not staged for commit:\n> >     (use \"git add <file>...\" to update what will be committed)\n> >     (use \"git restore <file>...\" to discard changes in working directory)\n> >         modified:   C2.java\n> >      > git add C1.java\n> >      > git add C2.java\n> >      > git commit -m \"commit2\"\n> >      D:\\gittest>git commit -m \"commit1\"\n> >      [master 91ef45d] commit1\n> >      1 file changed, 1 insertion(+), 1 deletion(-)\n> >\n> > In commit1 there is only one file, which is C2.java.\n>\n> It does say \"1 file changed\", which is true.\n> What it fails to mention is all the other files that are included within\n> the commit, but are unchanged.\n>\n> Maybe have a look at\n> https://git-scm.com/docs/git-ls-tree#Documentation/git-ls-tree.txt---name-status,\n> probably with the -r option (check the command's description)\n>\n> What Git version & OS are you on?\n> > This is a useful feature: one can stage all its files without\n> > bothering to remember\n> > which one had been changed, and then make a commit, and place the commands\n> > to do it in a script to be used each time a new commit is needed.\n> >\n> > -Angelo\n> >     ...\n> >\n> > On Thu, 27 Oct 2022 at 17:10, Philip Oakley <philipoakley@iee.email> wrote:\n> >> Hi,\n> >> On 27/10/2022 12:53, Angelo Borsotti wrote:\n> >>> Hello,\n> >>>\n> >>> the reference manual for the \"git add\" command does not\n> >>> specify what that command does when applied to an\n> >>> unmodified file.\n> >> I presume that this file is already tracked..\n> >>> By testing this, I have seen that it does not add the file\n> >>> to the index,\n> >> How was this tested?\n> >>\n> >> If you have no changes, thaen the status diff will have no mention of\n> >> that file.\n> >> Perhaps change the tracked mode bits to see if that is noticed (note\n> >> though, not all mode bits are tracked..)\n> >>> and consequently it does not add it when a\n> >>> subsequent commit is done.\n> >> I suspect this is a subtle mental model misunderstanding about the\n> >> distinction between a commit as a snapshot, and a commit being reported\n> >> as the diff relative to its parent (and here, there is none, if the file\n> >> is unmodified)\n> >>> I think that this should be documented.\n> >> A test script with sample output would help here.\n> >> --\n> >> Philip\n> >>\n> >>\n>\n"},{"id":"465881","messageId":"xmqqo7txmazv.fsf@gitster.g","threadId":"58701","inReplyTo":"CAB9Jk9DPdVmmb2DPDKPm5FLGr-XJa5kNouCYmcjh534Y2z1rVQ@mail.gmail.com","subject":"Re: Git add documentation error","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-10-27T17:28:52Z","receivedAt":"2022-10-27T17:28:57Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Angelo Borsotti <angelo.borsotti@gmail.com> writes:\n\n> Then I displayed the contents of both commits, and seen that it is pretty much\n> the same:\n>\n> D:\\gittest>git show --pretty=\"\" --name-only 91ef45d\n> C2.java\n>\n> D:\\gittest>git show --pretty=\"\" --name-only 8ec0c2f\n> C2.java\n\nYou did not display the contents of these commits, though.  For each\nof these commits, you checked the _difference_ between it and its\nparent.\n\nIn the previous sequence\n\n>> > I have tested this in the following way: I have two files: C1.java and C2.java\n>> >\n>> >     > git status\n>> >     On branch master\n>> >     nothing added to commit\n>> >     > ... edit C2.java\n>> >     > git status\n>> >     On branch master\n>> >     Changes not staged for commit:\n>> >     (use \"git add <file>...\" to update what will be committed)\n>> >     (use \"git restore <file>...\" to discard changes in working directory)\n>> >         modified:   C2.java\n>> >      > git add C1.java\n>> >      > git add C2.java\n>> >      > git commit -m \"commit2\"\n>> >      D:\\gittest>git commit -m \"commit1\"\n>> >      [master 91ef45d] commit1\n>> >      1 file changed, 1 insertion(+), 1 deletion(-)\n\n91ef45d, relative to its parent (i.e. the previous state before the\ncommit was made), C2.java was modified.  C1.java was not.\n\nSo, what you saw\n\n> D:\\gittest>git show --pretty=\"\" --name-only 91ef45d\n> C2.java\n\nis very much consistent with what you did.  And the above does not\nmean 91ef45d does not have C1.java.  If you want to \"display\" the\ncontents of commit 91ef45d, you could\n\n\t$ git ls-tree -r --name-only 91ef45d\n\nwhich lists all the contents in commit 91ef45d\n\nor\n\n\t$ git diff --name-only $(git hash-object --stdin -t tree </dev/null) 91ef45d\n\nwhich compares all the contents in commit 91ef45d with a completely\nempty tree.\n\nIn them, you'd see both C1 and C2, among other things that you did\nnot modify in 91ef45d.\n"},{"id":"465886","messageId":"CAB9Jk9BC1PVxuuNggZuDh1OMe3kdTvCzwkoo7Bkm35nRqAaL4g@mail.gmail.com","threadId":"58701","inReplyTo":"xmqqo7txmazv.fsf@gitster.g","subject":"Re: Git add documentation error","fromName":"Angelo Borsotti","fromEmail":"angelo.borsotti@gmail.com","sentAt":"2022-10-27T17:46:52Z","receivedAt":"2022-10-27T17:47:44Z","isPatch":false,"sender":{"key":"angelo.borsotti@gmail.com","avatar":null},"body":"Hi\n\nI have displayed the contents of the commits with the command you indicate,\nbut they still look much the same:\n\nD:\\gittest>git ls-tree -r --name-only 91ef45d\nC1.java\nC2.java\nC3.java\nC4.java\nC5.java\n\n\nD:\\gittest>git ls-tree -r --name-only 8ec0c2f\nC1.java\nC2.java\nC3.java\nC4.java\nC5.java\n\nI thought that in the second one I would see only the changed file.\n\n-Angelo\n\nOn Thu, 27 Oct 2022 at 19:28, Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Angelo Borsotti <angelo.borsotti@gmail.com> writes:\n>\n> > Then I displayed the contents of both commits, and seen that it is pretty much\n> > the same:\n> >\n> > D:\\gittest>git show --pretty=\"\" --name-only 91ef45d\n> > C2.java\n> >\n> > D:\\gittest>git show --pretty=\"\" --name-only 8ec0c2f\n> > C2.java\n>\n> You did not display the contents of these commits, though.  For each\n> of these commits, you checked the _difference_ between it and its\n> parent.\n>\n> In the previous sequence\n>\n> >> > I have tested this in the following way: I have two files: C1.java and C2.java\n> >> >\n> >> >     > git status\n> >> >     On branch master\n> >> >     nothing added to commit\n> >> >     > ... edit C2.java\n> >> >     > git status\n> >> >     On branch master\n> >> >     Changes not staged for commit:\n> >> >     (use \"git add <file>...\" to update what will be committed)\n> >> >     (use \"git restore <file>...\" to discard changes in working directory)\n> >> >         modified:   C2.java\n> >> >      > git add C1.java\n> >> >      > git add C2.java\n> >> >      > git commit -m \"commit2\"\n> >> >      D:\\gittest>git commit -m \"commit1\"\n> >> >      [master 91ef45d] commit1\n> >> >      1 file changed, 1 insertion(+), 1 deletion(-)\n>\n> 91ef45d, relative to its parent (i.e. the previous state before the\n> commit was made), C2.java was modified.  C1.java was not.\n>\n> So, what you saw\n>\n> > D:\\gittest>git show --pretty=\"\" --name-only 91ef45d\n> > C2.java\n>\n> is very much consistent with what you did.  And the above does not\n> mean 91ef45d does not have C1.java.  If you want to \"display\" the\n> contents of commit 91ef45d, you could\n>\n>         $ git ls-tree -r --name-only 91ef45d\n>\n> which lists all the contents in commit 91ef45d\n>\n> or\n>\n>         $ git diff --name-only $(git hash-object --stdin -t tree </dev/null) 91ef45d\n>\n> which compares all the contents in commit 91ef45d with a completely\n> empty tree.\n>\n> In them, you'd see both C1 and C2, among other things that you did\n> not modify in 91ef45d.\n"},{"id":"465892","messageId":"xmqq1qqtm7i0.fsf@gitster.g","threadId":"58701","inReplyTo":"CAB9Jk9BC1PVxuuNggZuDh1OMe3kdTvCzwkoo7Bkm35nRqAaL4g@mail.gmail.com","subject":"Re: Git add documentation error","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-10-27T18:44:23Z","receivedAt":"2022-10-27T18:44:28Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Angelo Borsotti <angelo.borsotti@gmail.com> writes:\n\n> Hi\n>\n> I have displayed the contents of the commits with the command you indicate,\n> but they still look much the same:\n>\n> D:\\gittest>git ls-tree -r --name-only 91ef45d\n> C1.java\n> C2.java\n> C3.java\n> C4.java\n> C5.java\n>\n>\n> D:\\gittest>git ls-tree -r --name-only 8ec0c2f\n> C1.java\n> C2.java\n> C3.java\n> C4.java\n> C5.java\n>\n> I thought that in the second one I would see only the changed file.\n\nGit tracks contents.  What it means is that you should stop thinking\nin terms of \"changed files\".  Each commit (and its tree) represents\na complete snapshot.  Back when you created 8ec0c2f, did you or did\nyou not have C1.java?  You said you did not modify it, so I assume\nyou did have it.  As a commit is a complete snapshot of the\ncontents, when you list the contents of 8ec0c2f, it should be\nincluded.\n\nTo put it another way, if you \"git checkout --detach 8ec0c2f\" in\norder to go back to the state you were back when you created that\ncommit, do you or do you not want to see C1.java and C2.java?  In\norder to be able to reproduce the then-current state, of course\nyou do want to see, and because each commit is a complete snapshot,\nyou can see C1 and C2.\n\n\"git add C1.java\" is a way to make sure that, if you make a commit,\nthe resulting \"snapshot\" includes the current contents stored in the\nC1.java file as you have on the filesystem at the time of issuing\n\"git add\" command.  If you made or did not make changes to C1.java\nbefore running \"git add C1.java\" is immaterial.  We may optimize out\nand make it a no-op if we know you did not make any changes, but it\ndoes not change the fact that the resulting commit will store, and\nmore importantly, you will be able to recover, the then-current\ncontents of C1.java out of that commit.\n"},{"id":"465895","messageId":"CAB9Jk9D1g3a+AHoPneMAzc6uTiW89zYQ32cNFJtxFZ71Eh9QHQ@mail.gmail.com","threadId":"58701","inReplyTo":"xmqq1qqtm7i0.fsf@gitster.g","subject":"Re: Git add documentation error","fromName":"Angelo Borsotti","fromEmail":"angelo.borsotti@gmail.com","sentAt":"2022-10-27T19:15:31Z","receivedAt":"2022-10-27T19:15:49Z","isPatch":false,"sender":{"key":"angelo.borsotti@gmail.com","avatar":null},"body":"Hi Junio,\n\n> Git tracks contents.  What it means is that you should stop thinking\n> in terms of \"changed files\".  Each commit (and its tree) represents\n> a complete snapshot.\n\nSure. I know it well and know that this is one of the most important\nfeatures of git.\n\n> \"git add C1.java\" is a way to make sure that, if you make a commit,\n> the resulting \"snapshot\" includes the current contents stored in the\n> C1.java file as you have on the filesystem at the time of issuing\n> \"git add\" command.\n\nThe behavior I have seen tells me that the safest thing to do is to\nhave a list of the files of the software, and build a script that makes\na git add for each of them, to be run each time before I make a commit.\n\nConcerning the fact that changes are somehow \"immaterial\", this is\ngood for a software that is developed by one person, but when there\nare several, and the released software has some unwanted changes\nin it, one may wonder who changed what. It could happen that a developer\nadded some changes of his own without telling anybody (perhaps using\nfiles that he has prepared for a next version).\n\nHave a good night\n-Angelo\n\nOn Thu, 27 Oct 2022 at 20:44, Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Angelo Borsotti <angelo.borsotti@gmail.com> writes:\n>\n> > Hi\n> >\n> > I have displayed the contents of the commits with the command you indicate,\n> > but they still look much the same:\n> >\n> > D:\\gittest>git ls-tree -r --name-only 91ef45d\n> > C1.java\n> > C2.java\n> > C3.java\n> > C4.java\n> > C5.java\n> >\n> >\n> > D:\\gittest>git ls-tree -r --name-only 8ec0c2f\n> > C1.java\n> > C2.java\n> > C3.java\n> > C4.java\n> > C5.java\n> >\n> > I thought that in the second one I would see only the changed file.\n>\n> Git tracks contents.  What it means is that you should stop thinking\n> in terms of \"changed files\".  Each commit (and its tree) represents\n> a complete snapshot.  Back when you created 8ec0c2f, did you or did\n> you not have C1.java?  You said you did not modify it, so I assume\n> you did have it.  As a commit is a complete snapshot of the\n> contents, when you list the contents of 8ec0c2f, it should be\n> included.\n>\n> To put it another way, if you \"git checkout --detach 8ec0c2f\" in\n> order to go back to the state you were back when you created that\n> commit, do you or do you not want to see C1.java and C2.java?  In\n> order to be able to reproduce the then-current state, of course\n> you do want to see, and because each commit is a complete snapshot,\n> you can see C1 and C2.\n>\n> \"git add C1.java\" is a way to make sure that, if you make a commit,\n> the resulting \"snapshot\" includes the current contents stored in the\n> C1.java file as you have on the filesystem at the time of issuing\n> \"git add\" command.  If you made or did not make changes to C1.java\n> before running \"git add C1.java\" is immaterial.  We may optimize out\n> and make it a no-op if we know you did not make any changes, but it\n> does not change the fact that the resulting commit will store, and\n> more importantly, you will be able to recover, the then-current\n> contents of C1.java out of that commit.\n"}]}