1

In my Git repo, I changed some files. I want to stage all of them. But is there a difference between commands:

git add file1.php file2.php

git add .

Does the second command stage only modified files, or all files from project? Or these commands are equal?

3 Answers 3

7

git add file1.php file2.php stages the files file1.php and file2.php.

git add . stages all files in the directory and all subdirectories, including uncommitted ones. (As long as they're not ignored by your .gitignore)

Either command will only stage a file if it's been modified, however.

Sign up to request clarification or add additional context in comments.

2 Comments

Your last sentence is a little misleading. It's more accurate to say that staging an unmodified file is a no-op: the staging area already implicitly contains the unmodified version. Further, both commands will also stage new files.
@Jefromi, true, if you think of the index as storing the full tree of the next commit, rather than just the difference between the HEAD and the next commit. Which is the correct way to think of it, of course, but that might not be obvious to a git newcomer.
1

If file1.php and file2.php are the only files that have changed or are untracked the two commands are equivalent, because unchanged files can't be staged anyway.

Comments

0

As explained by Sebastian P., these commands are not equavalent.

To stage all modified files, you can use git add -u

Also, for a quick commit of all modified files, you can use git commit -a which is equivalent to git add -u ; git commmit

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.