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

后端 未结 5 1648
挽巷
挽巷 2020-12-29 19:55

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

相关标签:
5条回答
  • 2020-12-29 20: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

    0 讨论(0)
  • 2020-12-29 20:12

    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.

    0 讨论(0)
  • 2020-12-29 20:18

    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.

    0 讨论(0)
  • 2020-12-29 20:18

    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.

    0 讨论(0)
  • 2020-12-29 20:26

    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.

    0 讨论(0)
提交回复
热议问题