简体   繁体   English

git add和git commit -a之间的区别

[英]Difference between git add and git commit -a

I am trying to better understand how git works. 我试图更好地了解git的工作原理。

So we have a working directory (our project files), a staging area (a collection of changes ready to go), and a git repository (where those changes are applied to when committed). 因此,我们有一个工作目录(我们的项目文件),一个暂存区(准备好进行更改的集合)和一个git存储库(在提交时将这些更改应用于其中)。

However I am struggling to understand because it seems like files being "tracked" or not refer to some specific thing, and yet we still say each section does its own form of tracking? 但是,我很难理解,因为似乎文件被“跟踪”或未引用某些特定的东西,但是我们仍然说每个部分都有自己的跟踪形式吗?

Is it correct to say: 说的正确吗?

  1. If I add or modify a file in my working directory, git detects all of this. 如果我在工作目录中添加或修改文件,则git会检测到所有这些。 Do we say that these files become "tracked" by git at this point? 我们是否说此时这些文件已被git“跟踪”? Or are they merely "detected" (or something else)? 还是仅仅是“被发现”(或其他)? Is everything in the project folder / working directory "tracked"? 项目文件夹/工作目录中的所有内容是否都已“跟踪”?

  2. git add {directory or filename} appears to add the contents to the staging area, yes? git add {directory or filename}出现,将内容添加到登台区域,是吗? At this point do we say all staged files are "tracked" files, the ones that show up when we do git ls-files , which I believe shows the files in the staging area? 在这一点上,我们是否说所有暂存的文件都是“跟踪”文件,即执行git ls-files显示的文件,我相信这些文件会在暂存区域中显示? Or no? 或者没有?

  3. git commit -a moves all the changes in the staging area to the repository. git commit -a将登台区域中的所有更改移至存储库。

Is this correct? 这个对吗?

git add adds files to be tracked as well as staging (the current commit) git add添加要跟踪和暂存的文件(当前提交)

git commit -a adds files to staging only if they are already tracked git commit -a 在文件已被跟踪时才将文件添加到暂存中

Git notices files that are not on tracked when they are added to the repo directory because it understands them as a file change. 当将文件添加到repo目录时,Git会注意到未跟踪的文件,因为它将它们理解为文件更改。 But unless you explicitly add them to the tracking it will not track any change increments 但是,除非您将它们明确添加到跟踪中,否则它将不会跟踪任何更改增量

This question may help you: Concept of git tracking and git staging 这个问题可能会对您有所帮助: git跟踪和git暂存的概念

Also see this https://www.howtogit.net/concepts/types-of-changes.html 另请参阅此https://www.howtogit.net/concepts/types-of-changes.html

I think the main point of our confusion is that git add can do two things (add to tracking if not already, and stage) whereas git commit -a only does one (add tracked files to the stage) 我认为我们混淆的重点是git add可以做两件事(如果尚未添加,请添加到跟踪,然后执行阶段),而git commit -a只做一件事(将跟踪的文件添加到该阶段)

  1. If I add or modify a file in my working directory, git detects all of this. 如果我在工作目录中添加或修改文件,则git会检测到所有这些。 Do we say that these files become "tracked" by git at this point? 我们是否说此时这些文件已被git“跟踪”? Or are they merely "detected" (or something else)? 还是仅仅是“被发现”(或其他)? Is everything in the project folder / working directory "tracked"? 项目文件夹/工作目录中的所有内容是否都已“跟踪”?

Git detects modified and deleted files. Git检测修改和删除的文件。 If they are tracked (ie they were added before and committed) they appear in the output of git status as "modified". 如果跟踪了它们(即,它们是在之前添加并提交的),则它们在git status的输出中显示为“ modified”。 The new files and the modified files that are not tracked appear as "untracked". 未跟踪的新文件和修改的文件显示为“未跟踪”。

  1. git add {directory or filename} appears to add the contents to the staging area, yes? git add {directory or filename}出现,将内容添加到登台区域,是吗? At this point do we say all staged files are "tracked" files, the ones that show up when we do git ls-files , which I believe shows the files in the staging area? 在这一点上,我们是否说所有暂存的文件都是“跟踪”文件,即执行git ls-files显示的文件,我相信这些文件会在暂存区域中显示? Or no? 或者没有?

The staging area is used to prepare the next commit. 暂存区用于准备下一次提交。 You can say the files it contains are "tracked" but its content is not permanent; 您可以说其中包含的文件是“已跟踪”的,但其内容不是永久的; it can be changed any time. 可以随时更改。 In order to turn a new file really "tracked" by Git you have to commit the staged changes. 为了打开一个由Git真正“跟踪”的新文件,您必须提交已暂存的更改。

  1. git commit -a moves all the changes in the staging area to the repository. git commit -a将登台区域中的所有更改移至存储库。

git commit creates a new commit using the staged content. git commit使用暂存的内容创建一个新的提交。 git commit -a automatically stage tracked files that were changed or deleted and then operates the commit. git commit -a自动git commit -a已更改或删除的跟踪文件,然后操作提交。 The new files are not added. 没有添加新文件。

Read more about git commit and about how Git records the changes to the repository . 阅读有关git commitGit如何将更改记录到存储库的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM