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

Re: [PATCH 2/5] doc: git-add: start man page with an example

From
D. Ben Knoble <ben.knoble@gmail.com>
Date
Aug 13, 2025, 17:22 UTC
Message-ID
<CALnO6CCjW=W4A7d4se8fCe7gzuDLc-SyGv7JbVqbtSSkSM1bNg@mail.gmail.com>
In-Reply-To
<152d47a3-7744-476a-8ab8-43b7b52b67ea@app.fastmail.com>
On Tue, Aug 12, 2025 at 5:40 PM Julia Evans <julia@jvns.ca> wrote:
Show 11 quoted lines
>
> > But isn't it the source of the most end-user confusion that they
> > cannot wean themselves off of the diff/patch worldview?
>
> To me it feels very contextual! My impression is that what's important for Git
> users is to be able to think about commits as diffs in some contexts, and as
> snapshots in other contexts. For example with `git rebase` I'm usually thinking
> of my commits as diffs, but it's very helpful to me to think of a merge commit
> as a snapshot, because the merge commit does not have to be a "combination" of
> the two sides of the merge, it can have arbitrary extra content.
>
[snip]
Show 37 quoted lines
>
> >> +By default, `git commit` only commits changes that you've added to the
> >> +index. For example, if you've edited `file.c` and want to commit your
> >> +changes, you can run:
> >> +
> >> +   git add file.c
> >> +   git commit
> >
> > What happens when you did "edit && add && edit && add"?  It commits
> > the two changes you added to the index?  I do not think it is
> > productive to hide the fact that you are preparing a snapshot of the
> > "next commit" in the index (or "staging the contents for the next
> > commit in the staging area") with various forms "git add", including
> > "git add -p".
>
> It could! It's easy for me to imagine a world where the index
> stores an ordered list of diffs, which are applied as patches in
> series when I commit. I guess you'd need some sort of
> patch + patch + patch + diff workflow to generate the final diff,
> but to me that doesn't feel so different from what Git is actually doing in
> practice.
>
> In any case, I'll think more about whether I think this is really
> an accurate description. I'm always especially interested in the practical
> consequences of having misconceptions about Git: for example (and maybe I'm
> convincing myself to change my position here!) with `git mv` I think it can
> become relevant pretty quickly that commits are snapshots, because if
> you move a file and edit it then Git can't always accurately guess that you
> intended to "move" the file rather than delete the file and create a new one.
>
> I'd like to be able to have a similarly practical example of why it's important
> to think of commits as snapshots in the context of `git add` but I haven't quite
> found the right one yet. I've noticed that people will often sort of "reject"
> information that does not fit their mental models, and I think "commits are
> snapshots, this is important in this context because of
> <specific practical consequence>" is much more convincing than just
> "commits are snapshots".

Less a comment on this patch or diff ;) and more a meta-note: I happen to have several links saved on the idea of "Snapshot vs. Patch" aka "commit duality", so I figured I'd share. They reinforce to me, at least, that the contextual mode of thinking is useful in practice, even if the snapshot model is the (semantic) storage model [*]. Knowing about snapshots does make it far easier to interact with objects directly, which also frequently helps me better understand how to use particular commands.

- https://www.thirtythreeforty.net/posts/2020/01/the-wave-particle-duality-of-git-commits/
- https://roadrunnertwice.dreamwidth.org/596185.html (which references
Julia's work)
- of course, https://jvns.ca/blog/2024/01/05/do-we-think-of-git-commits-as-diffs--snapshots--or-histories/
;)
- https://stackoverflow.com/q/40617288/4400820,
https://stackoverflow.com/q/73646342/4400820,
https://stackoverflow.com/a/27760319/4400820
- https://github.blog/open-source/git/commits-are-snapshots-not-diffs/
- https://lore.kernel.org/git/alpine.LFD.0.98.0705090856220.4062@woody.linux-foundation.org/

What I find is that, while we keep trying to reinforce the snapshot mentality, there are situations where thinking in diffs is a reasonable approximation. In the particular case of git-add, most interactions I observe with the index are diff-based (git diff, git diff --cached, etc.), but I'm not sure how to usefully clarify the relationship between those things and the underlying trees involved (working tree, HEAD, index :0:) in a manual section targeted primarily at newcomers.

[*]: "Semantic" because deltas in packfiles muddy the _actual_ storage model somewhat :)

-- 
D. Ben Knoble
Previous: Julia EvansNext: Junio C Hamano
Message 11 of 59 in “doc: git-add: clarify DESCRIPTION section”
  1. 0/5 doc: git-add: clarify DESCRIPTION sectionJulia Evans via GitGitGadget, Aug 12, 2025
  2. 1/5 doc: git-add: remove options from SYNOPSISJulia Evans via GitGitGadget, Aug 12, 2025
  3. Junio C HamanoAug 12, 2025
  4. Julia EvansAug 13, 2025
  5. Jean-Noël AVILAAug 13, 2025
  6. 2/5 doc: git-add: start man page with an exampleJulia Evans via GitGitGadget, Aug 12, 2025
  7. Junio C HamanoAug 12, 2025
  8. Julia EvansAug 12, 2025
  9. Junio C HamanoAug 12, 2025
  10. Julia EvansAug 12, 2025
  11. D. Ben KnobleAug 13, 2025
  12. Junio C HamanoAug 14, 2025
  13. Julia EvansAug 14, 2025
  14. Junio C HamanoAug 15, 2025
  15. 3/5 doc: git-add: simplify discussion of ignored filesJulia Evans via GitGitGadget, Aug 12, 2025
  16. D. Ben KnobleAug 13, 2025
  17. 4/5 doc: git-add: make explanation less dryJulia Evans via GitGitGadget, Aug 12, 2025
  18. 5/5 doc: git-add: explain inconsistent terminologyJulia Evans via GitGitGadget, Aug 12, 2025
  19. Chris TorekAug 12, 2025
  20. Junio C HamanoAug 12, 2025
  21. Julia EvansAug 12, 2025
  22. 0/4 doc: git-add: clarify DESCRIPTION sectionJulia Evans via GitGitGadget, Aug 13, 2025
  23. 1/4 doc: git-add: start man page with an exampleJulia Evans via GitGitGadget, Aug 13, 2025
  24. Junio C HamanoAug 15, 2025
  25. Jean-Noël AVILAAug 15, 2025
  26. Junio C HamanoAug 15, 2025
  27. Jean-Noël AVILAAug 17, 2025
  28. Julia EvansAug 19, 2025
  29. 2/4 doc: git-add: simplify discussion of ignored filesJulia Evans via GitGitGadget, Aug 13, 2025
  30. D. Ben KnobleAug 14, 2025
  31. Junio C HamanoAug 14, 2025
  32. 3/4 doc: git-add: make explanation less dryJulia Evans via GitGitGadget, Aug 13, 2025
  33. Junio C HamanoAug 14, 2025
  34. Julia EvansAug 15, 2025
  35. D. Ben KnobleAug 15, 2025
  36. Junio C HamanoAug 15, 2025
  37. D. Ben KnobleAug 16, 2025
  38. Junio C HamanoAug 15, 2025
  39. Julia EvansAug 19, 2025
  40. Jean-Noël AVILAAug 21, 2025
  41. 4/4 doc: git-add: explain inconsistent terminologyJulia Evans via GitGitGadget, Aug 13, 2025
  42. Junio C HamanoAug 14, 2025
  43. Julia EvansAug 19, 2025
  44. 0/3 doc: git-add: clarify DESCRIPTION sectionJulia Evans via GitGitGadget, Aug 19, 2025
  45. 1/3 Git 2.51Junio C Hamano via GitGitGadget, Aug 19, 2025
  46. rsbecker@nexbridge.comAug 19, 2025
  47. Junio C HamanoAug 19, 2025
  48. D. Ben KnobleAug 19, 2025
  49. Julia EvansAug 19, 2025
  50. rsbecker@nexbridge.comAug 19, 2025
  51. 3/3 doc: git-add: simplify discussion of ignored filesJulia Evans via GitGitGadget, Aug 19, 2025
  52. Junio C HamanoAug 21, 2025
  53. 2/3 doc: git-add: clarify intro & add an exampleJulia Evans via GitGitGadget, Aug 19, 2025
  54. Junio C HamanoAug 21, 2025
  55. Julia EvansAug 22, 2025
  56. 0/2 doc: git-add: clarify DESCRIPTION sectionJulia Evans via GitGitGadget, Aug 29, 2025
  57. 1/2 doc: git-add: clarify intro & add an exampleJulia Evans via GitGitGadget, Aug 29, 2025
  58. 2/2 doc: git-add: simplify discussion of ignored filesJulia Evans via GitGitGadget, Aug 29, 2025
  59. Junio C HamanoAug 29, 2025

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.