没有 -a 选项的 git commit 有什么影响?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2807899/
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-19 04:16:05  来源:igfitidea点击:

What is the effect of git commit without the -a option?

gitcommit

提问by ben

What is the difference between these two commands?

这两个命令有什么区别?

git commit -m "added a new page"

and

git commit -a -m "added a new page"

I know that the -a option will stage files that have been modified and deleted, but then what does running it without the -a mean?

我知道 -a 选项将暂存已修改和删除的文件,但是没有 -a 的情况下运行它意味着什么?

回答by John Weldon

You have to explicitly stage changes for commitment by using git addor git rm.

您必须使用git add或明确地为承诺进行更改git rm

If you use the -aflag when doing a commit, git will automatically stage any modified and removed files without you having to explicitly stage them using addor rm, etc.

如果您在-a提交时使用该标志,git 将自动暂存任何修改和删除的文件,而无需您使用addrm等明确暂存它们。

If you don'tspecify -a, any files that have been modified or removed, but not explicitly staged using git addor git rmwill be ignored in the commit.

如果指定-a,则任何已修改或删除但未使用git add或显式暂存的文件git rm将在提交中被忽略。

update

更新

As Dr. Gianluigi Zane Zanettini says - -adoes not add newfiles to the index, so if you have completely new files you shouldn't expect -ato ad them.

正如 Gianluigi Zane Zanetini 博士所说 --a不会将文件添加到索引中,因此如果您有全新的文件,则不应期望-a添加它们。

http://www.kernel.org/pub/software/scm/git/docs/git-commit.html

http://www.kernel.org/pub/software/scm/git/docs/git-commit.html