Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't git commit -a add new files?

Tags:

git

dvcs

commit

I'm a bit new to git, and I fail to understand why git commit -a only stages changed and deleted files but not new files.

Can anyone explain why is it like this, and why there is no other commit flag to enable adding files and committing in one command?

BTW, hg commit -A adds both new and deleted files to the commit

like image 581
splintor Avatar asked May 03 '10 16:05

splintor


People also ask

Does git commit add new files?

It only adds the content of the specified file(s) at the time the add command is run; if you want subsequent changes included in the next commit, then you must run git add again to add the new content to the index.

How do I add files to an existing commit?

You can modify the most recent commit in the same branch by running git commit –amend. This command is convenient for adding new or updated files to the previous commit. It is also a simple way to edit or add comments to the previous commit. Use git commit –amend to modify the most recent commit.

How do I commit changes to a file?

Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed. Enter git commit -m '<commit_message>' at the command line to commit new files/changes to the local repository.

What is the git commit command?

The git commit command captures a snapshot of the project's currently staged changes. Committed snapshots can be thought of as “safe” versions of a project—Git will never change them unless you explicitly ask it to.


2 Answers

Git is about tracking changes. It relies on you to tell it which files are important enough to track. You can achieve the desired affect like so:

git add . ;git commit -a 

Make sure your .gitignore file is updated.

like image 80
Kelly S. French Avatar answered Sep 22 '22 01:09

Kelly S. French


I suggest another solution: using git commit --interactive -m "your commit message" will show you this menu

*** Commands ***
  1: [s]tatus     2: [u]pdate     3: [r]evert     4: [a]dd untracked
  5: [p]atch      6: [d]iff   7: [q]uit   8: [h]elp

allowing you to check status, add untracked files and so on using simple keystrokes.

like image 40
Gonzalo Cao Avatar answered Sep 21 '22 01:09

Gonzalo Cao