开发者

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

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 comma开发者_高级运维nd?

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


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.


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.


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜