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

Re: Question about "git commit -a"

From
Andreas Ericsson <ae@op5.se>
Date
Oct 5, 2007, 12:23 UTC
Message-ID
<47062CD7.70400@op5.se>
In-Reply-To
<4d8e3fd30710050519k7a3db02dk5ba9750fd8e9705f@mail.gmail.com>
Paolo Ciarrocchi wrote:
Show 47 quoted lines
> On 10/5/07, Andreas Ericsson <ae@op5.se> wrote:
> [...]
>> As for the "git commit should default to -a" discussion, I think it's pretty
>> clear where I stand ;-)
> 
> Fair enough.
> 
> Another try to have an easy explanation of how the staging area works:
> 
> paolo@paolo-desktop:~/HowIndexWorks$ ls
> A  B  C  D  E  F  G
> 
> Now I edit A,B,C,D and E:
> 
> $ echo A >> A
> $ echo B >> B
> $ echo C >> C
> $ echo D >> D
> $ echo E >> E
> 
> I now realize want to only commit the changes I did to A,B,C,D.
> First step is to place A,B,C and D into the staging area:
> $ git add A B C D
> 
> Now I can commit:
> $ git commitpaolo@paolo-desktop:~/HowIndexWorks$ git commit
> Created commit 16032dc: I modified A,B,C and D
>  4 files changed, 4 insertions(+), 0 deletions(-)
> 
> It's now time to work on F and G:
> $ echo F >> F
> $ echo G >> G
> 
> Current status is:
> paolo@paolo-desktop:~/HowIndexWorks$ git status
> # On branch master
> # Changed but not updated:
> #   (use "git add <file>..." to update what will be committed)
> #
> #       modified:   E
> #       modified:   F
> #       modified:   G
> 
> Instead of adding E,F and G to the staging are and then commit them in
> two steps I can using a single command:
> $ git commit E F G (in this case it's equivalent to git commit -a)
> 

He. It's like comparing a duracell battery to the sun, but yes, that's one of the operations where the index is involved. But after doing your git-add thing above, you could also have continued hacking on A B C D, and git would only have committed the state where you did "git add". When you stop to think about this, you'll realize that it's a really powerful thing, as it lets you keep on hacking even when you don't really know where you'll end up.

-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
Previous: Paolo CiarrocchiNext: Matthieu Moy
Message 18 of 35 in “Question about "git commit -a"”
  1. Paolo CiarrocchiOct 4, 2007
  2. Matthieu MoyOct 4, 2007
  3. Paolo CiarrocchiOct 4, 2007
  4. Wincent ColaiutaOct 4, 2007
  5. Nguyen Thai Ngoc DuyOct 4, 2007
  6. Johannes SchindelinOct 4, 2007
  7. Nguyen Thai Ngoc DuyOct 4, 2007
  8. Shawn O. PearceOct 4, 2007
  9. Paolo CiarrocchiOct 5, 2007
  10. Andreas EricssonOct 5, 2007
  11. Paolo CiarrocchiOct 5, 2007
  12. Andreas EricssonOct 5, 2007
  13. Matthieu MoyOct 5, 2007
  14. Andreas EricssonOct 5, 2007
  15. Matthieu MoyOct 5, 2007
  16. Andreas EricssonOct 5, 2007
  17. Paolo CiarrocchiOct 5, 2007
  18. Andreas EricssonOct 5, 2007
  19. Matthieu MoyOct 5, 2007
  20. Kristian HøgsbergOct 5, 2007
  21. Matthieu MoyOct 5, 2007
  22. Marko MacekOct 5, 2007
  23. Andy ParkinsOct 6, 2007
  24. Linus TorvaldsOct 6, 2007
  25. Wincent ColaiutaOct 7, 2007
  26. Dmitry PotapovOct 5, 2007
  27. Marko MacekOct 7, 2007
  28. Dmitry PotapovOct 7, 2007
  29. Johannes SchindelinOct 7, 2007
  30. Wincent ColaiutaOct 5, 2007
  31. Andy ParkinsOct 4, 2007
  32. Miles BaderOct 5, 2007
  33. David SoriaOct 4, 2007
  34. Alex RiesenOct 4, 2007
  35. Johannes SchindelinOct 4, 2007

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.