git 添加。vs git commit -a

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

git add . vs git commit -a

gitversion-controlgit-commitgit-addgit-commands

提问by Yarin

What's the difference between:

有什么区别:

  • git add .
  • git commit -a
  • git add .
  • git commit -a

Should I be doing both, or is that redundant?

我应该两者都做,还是多余的?

回答by CB Bailey

git commit -ameans almost[*] the same thing as git add -u && git commit.

git commit -a几乎 [*] 与git add -u && git commit.

It's not the same as git add .as this would add untracked files that aren't being ignored, git add -uonly stages changes (including deletions) to already tracked files.

这与git add .添加未被忽略的未跟踪文件不同,git add -u仅对已跟踪文件进行阶段更改(包括删除)。

[*] There's a subtle difference if you're not at the root directory of your repository. git add -ustages updates to files in the current directory and below, it's equivalent to git add -u .whereas git commit -astages and commits changes to alltracked files.

[*] 如果您不在存储库的根目录中,则存在细微差别。git add -u阶段更新的文件在当前目录及以下,这相当于git add -u .git commit -a阶段,并提交更改所有跟踪文件。

回答by alternative

git commit -aautomatically invokes git addon all files it knows about. You can use git addto select what files to commit. Consult the docs for more info: here

git commit -a自动调用git add它知道的所有文件。您可以使用git add来选择要提交的文件。有关更多信息,请参阅文档:here

回答by Dilip

By using the git commit -a switch with the commit command to automatically "add" changes from all known files (i.e. all files that are already listed in the index)

通过使用带有 commit 命令的 git commit -a 开关来自动“添加”所有已知文件(即已在索引中列出的所有文件)的更改