Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git add . vs git commit -a

What's the difference between:

  • git add .
  • git commit -a

Should I be doing both, or is that redundant?

like image 679
Yarin Avatar asked Aug 22 '10 13:08

Yarin


People also ask

When to use git add vs git commit?

git add : takes a modified file in your working directory and places the modified version in a staging area. git commit takes everything from the staging area and makes a permanent snapshot of the current state of your repository that is associated with a unique identifier.

Which comes first git add or git commit?

In review, git add is the first command in a chain of operations that directs Git to "save" a snapshot of the current project state, into the commit history. When used on its own, git add will promote pending changes from the working directory to the staging area.

What is the difference between git commit and git commit?

git commit -- takes the commit message from the given file. In the parameter you should enter the name of the file you want from your repository. git commit --only is the default mode of operation of git commit.


2 Answers

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.

like image 104
CB Bailey Avatar answered Sep 23 '22 05:09

CB Bailey


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

like image 37
alternative Avatar answered Sep 24 '22 05:09

alternative