git add . vs git commit -a
Asked Answered
T

3

123

What's the difference between:

  • git add .
  • git commit -a

Should I be doing both, or is that redundant?

Theine answered 22/8, 2010 at 13:34 Comment(1)
see also (not exact duplicate, though): #573049Throckmorton
T
163

git commit -a means almost[*] the same thing as git add -u && git commit.

It's not the same as git add . as this would add untracked files that aren't being ignored, git add -u only stages changes (including deletions) to already tracked files.

[*] There's a subtle difference if you're not at the root directory of your repository. git add -u stages updates to files in the current directory and below, it's equivalent to git add -u . whereas git commit -a stages and commits changes to all tracked files.

Throckmorton answered 22/8, 2010 at 13:36 Comment(4)
The behaviour in [*] will change in git 2.0, for consistency.Caracara
In which direction? i.e. will commit -a become like add -u, or will add -u become like commit -a?Peterpeterborough
@MilesRout: git add -u will become like git commit -a; you will need to explicitly say git add -u . if that is what you mean.Throckmorton
This is absolutely the same since Git v 2.0 where git add . behaves in a different way.Bushweller
L
15

git commit -a automatically invokes git add on all files it knows about. You can use git add to select what files to commit. Consult the docs for more info: here

Lousy answered 22/8, 2010 at 13:37 Comment(7)
all files it knows about is very unclear to me, especially since those were supposedly NOT addedCymogene
@Nikana Reklawyks You have the definition of "add" wrong. Add does not mean the same thing as it does in svn. All it does is update the index. [Sorry for slow response, I don't remember getting a notification for that comment]Lousy
@alternative, Still this answer can do better if you add a clarification for "all files it knows about".....Detainer
@Detainer equivalent to git add -uLousy
"all files it knows about" vaguely speaking would be existing files that were modified. Or, NOT new files.Sunup
@Z.Khullah, so "all (...)" means "tracked files"?Flickinger
@Flickinger precisely!Sunup
A
2

By using the git commit -a switch with the commit command to automatically "add" changes from all known files (i.e. all files that are already listed in the index)

Augmentation answered 7/4, 2018 at 18:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.