in Technology by
The command git add [--all|-A] appears to be identical to git add .. Is this correct? If not, how do they differ?

1 Answer

0 votes
by
 
Best answer
  • git add -A stages all changes

  • git add . stages new files and modifications, without deletions

  • git add -u stages modifications and deletions, without new files


Detail:

git add -A is equivalent to git add .; git add -u.

The important point about git add . is that it looks at the working tree and adds all those paths to the staged changes if they are either changed or are new and not ignored, it does not stage any 'rm' actions.

git add -u looks at all the already tracked files and stages the changes to those files if they are different or if they have been removed. It does not add any new files, it only stages changes to already tracked files.

git add -A is a handy shortcut for doing both of those.

You can test the differences out with something like this (note that for Git version 2.x your output for git add . git status will be different):

git init
echo Change me > change-me
echo Delete me > delete-me
git add change-me delete-me
git commit -m initial

echo OK >> change-me
rm delete-me
echo Add me > add-me

git status
# Changed but not updated:
#   modified:   change-me
#   deleted:    delete-me
# Untracked files:
#   add-me

git add .
git status

# Changes to be committed:
#   new file:   add-me
#   modified:   change-me
# Changed but not updated:
#   deleted:    delete-me

git reset

git add -u
git status

# Changes to be committed:
#   modified:   change-me
#   deleted:    delete-me
# Untracked files:
#   add-me

git reset

git add -A
git status

# Changes to be committed:
#   new file:   add-me
#   modified:   change-me
#   deleted:    delete-me

Related questions

0 votes
    What does the command git add . do? A. Adds all the files to repo B. Adds all the files to the staging area C. Adds all the files to the local directory D. None of the options...
asked Dec 17, 2022 in Education by JackTerrance
0 votes
    Three identical dice are rolled. The probability that same number appears on them, is A. 1 6 B. 1 36 C. 1 18 D. 3 28 Select the correct answer from above options...
asked Nov 15, 2021 in Education by JackTerrance
0 votes
    Is it possible to add a file directly to the repository? Which command can be used for this?...
asked Feb 18, 2021 in Technology by JackTerrance
0 votes
    How do I undo 'git add' before commit?...
asked Jan 7, 2021 in Technology by JackTerrance
0 votes
    What is ‘git reset’ is used for? What is the default mode of this command?...
asked Nov 4, 2020 in Technology by JackTerrance
0 votes
    What is Data Science? How do Supervised and Unsupervised Machine Learning differ?...
asked Apr 24, 2021 in Technology by JackTerrance
0 votes
    How do tibbles differ from the traditional data-frames?...
asked Oct 16, 2020 in Technology by JackTerrance
0 votes
    a) Harshita wants to create an HTML form. Which tag should she use to create this form? Her teacher has asked ... plz answer this fast Select the correct answer from above options...
asked Dec 14, 2021 in Education by JackTerrance
0 votes
    What is the Git command to view all the changes since the last commit ? A. git clean B. git status C. git changes D. git commit...
asked Dec 21, 2022 in Technology by JackTerrance
0 votes
    What is the Git command to view all the commits since 1st January 2017 ? A. show git log since Jan 1 2017 B. git log ... =”2017-01-01” C. git log D. None of the options...
asked Dec 21, 2022 in Technology by JackTerrance
0 votes
    What is the Git command to blow away all the changes in a file in the working area, since the previous commit? A. ... git log filename C. git checkout filename D. git rm filename...
asked Dec 21, 2022 in Technology by JackTerrance
0 votes
    How do pressure groups differ from social movements? Please answer the above question....
asked Aug 3, 2022 in Education by JackTerrance
0 votes
    A configurable ________ can be set to retain all published records in Kafka irrespective of whether they have been consumed ... (2)All the options (3)interval (4)retention period...
asked Jun 17, 2021 in Technology by JackTerrance
...