为什么不 git commit -a 添加新文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2759355/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 08:20:41  来源:igfitidea点击:

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

gitdvcscommit

提问by splintor

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

我对 git 有点陌生,我不明白为什么git commit -a只有阶段更改和删除文件而不是新文件。

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 -Aadds both new and deleted files to the commit

顺便说一句,hg commit -A将新文件和已删除文件都添加到提交中

回答by Kelly S. French

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 是关于跟踪变化的。它依赖于您告诉它哪些文件足够重要以进行跟踪。您可以像这样实现所需的效果:

git add . ;git commit -a

Make sure your .gitignorefile is updated.

确保您的.gitignore文件已更新。

回答by Gonzalo Cao

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

我建议另一种解决方案:使用git commit --interactive -m "your commit message"将显示此菜单

*** 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.

允许您使用简单的按键检查​​状态、添加未跟踪的文件等。

回答by Matt R

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.

我怀疑答案很简单(但我怀疑我会因为这样说而受欢迎!)——可能没有故意的“为什么”,除了开发人员实施它时它是如何失败的。Git 项目的优先级从来都不是易用性或用户友好性。

回答by JasonSmith

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.

Kelly 是对的,但我认为另一个因素是,很多人都期望这种行为,因为 CVS、Subversion 和大多数其他工具都是这样做的。

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

如果 Git 提交了新文件,您可能会注意到您.o很久以前就提交了文件,更糟糕的是它们可能会损害构建。

回答by Theophilus Omoregbee

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

为了将来,您可以坚持使用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

由于它不会从评论中太明显 https://stackoverflow.com/a/2419270/5836034