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

Re: Git add documentation error

From
ABAngelo Borsotti <angelo.borsotti@gmail.com>
Date
Oct 27, 2022, 17:46 UTC
Message-ID
<CAB9Jk9BC1PVxuuNggZuDh1OMe3kdTvCzwkoo7Bkm35nRqAaL4g@mail.gmail.com>
In-Reply-To
<xmqqo7txmazv.fsf@gitster.g>
Hi

I have displayed the contents of the commits with the command you indicate, but they still look much the same:

D:\gittest>git ls-tree -r --name-only 91ef45d C1.java C2.java C3.java C4.java C5.java

D:\gittest>git ls-tree -r --name-only 8ec0c2f C1.java C2.java C3.java C4.java C5.java

I thought that in the second one I would see only the changed file.
-Angelo
On Thu, 27 Oct 2022 at 19:28, Junio C Hamano <gitster@pobox.com> wrote:
Show 62 quoted lines
>
> Angelo Borsotti <angelo.borsotti@gmail.com> writes:
>
> > Then I displayed the contents of both commits, and seen that it is pretty much
> > the same:
> >
> > D:\gittest>git show --pretty="" --name-only 91ef45d
> > C2.java
> >
> > D:\gittest>git show --pretty="" --name-only 8ec0c2f
> > C2.java
>
> You did not display the contents of these commits, though.  For each
> of these commits, you checked the _difference_ between it and its
> parent.
>
> In the previous sequence
>
> >> > I have tested this in the following way: I have two files: C1.java and C2.java
> >> >
> >> >     > git status
> >> >     On branch master
> >> >     nothing added to commit
> >> >     > ... edit C2.java
> >> >     > git status
> >> >     On branch master
> >> >     Changes not staged for commit:
> >> >     (use "git add <file>..." to update what will be committed)
> >> >     (use "git restore <file>..." to discard changes in working directory)
> >> >         modified:   C2.java
> >> >      > git add C1.java
> >> >      > git add C2.java
> >> >      > git commit -m "commit2"
> >> >      D:\gittest>git commit -m "commit1"
> >> >      [master 91ef45d] commit1
> >> >      1 file changed, 1 insertion(+), 1 deletion(-)
>
> 91ef45d, relative to its parent (i.e. the previous state before the
> commit was made), C2.java was modified.  C1.java was not.
>
> So, what you saw
>
> > D:\gittest>git show --pretty="" --name-only 91ef45d
> > C2.java
>
> is very much consistent with what you did.  And the above does not
> mean 91ef45d does not have C1.java.  If you want to "display" the
> contents of commit 91ef45d, you could
>
>         $ git ls-tree -r --name-only 91ef45d
>
> which lists all the contents in commit 91ef45d
>
> or
>
>         $ git diff --name-only $(git hash-object --stdin -t tree </dev/null) 91ef45d
>
> which compares all the contents in commit 91ef45d with a completely
> empty tree.
>
> In them, you'd see both C1 and C2, among other things that you did
> not modify in 91ef45d.
Previous: Junio C HamanoNext: Junio C Hamano
Message 6 of 8 in “Git add documentation error”
  1. Angelo BorsottiOct 27, 2022
  2. Philip OakleyOct 27, 2022
  3. Philip OakleyOct 27, 2022
  4. Angelo BorsottiOct 27, 2022
  5. Junio C HamanoOct 27, 2022
  6. Angelo BorsottiOct 27, 2022
  7. Junio C HamanoOct 27, 2022
  8. Angelo BorsottiOct 27, 2022

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.