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

2019-03-17 05:33发布

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

标签: git dvcs commit
5条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-03-17 05:45

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.

查看更多
乱世女痞
3楼-- · 2019-03-17 05:56

I suspect the answer is simple (but I doubt I'll be popular for saying it!) -- there is likely no deliberate "why" to this, other than it's how it fell out when the developers implemented it. The priority of the Git project has never been on ease-of-use or user-friendliness.

查看更多
Evening l夕情丶
4楼-- · 2019-03-17 06:01

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.

查看更多
够拽才男人
5楼-- · 2019-03-17 06:03

For Future sake you can stick with this solution from Ian Clelland,

git add -A && git commit -m "Your Message"

Since it won't be too visible from comment https://stackoverflow.com/a/2419270/5836034

查看更多
老娘就宠你
6楼-- · 2019-03-17 06:07

Kelly is correct but I think another factor is that so many people expect that behavior because CVS, Subversion, and most other tools do it that way.

If Git committed new files, you might notice that you had committed .o files long ago and even worse they might harm the build.

查看更多
登录 后发表回答