简体   繁体   English

Git Staging区域的功能

[英]Function of Git Staging area

I have gone through Git object model and read other articles about git but couldn't understand clearly about Git staging area . 我已经浏览了Git对象模型并阅读关于git的其他文章 ,但无法清楚地了解Git staging area

What does staging area actually do? 临时区域实际上做了什么?

Does it create the blob object and tree object when we do git add and when we do git commit the commit object is linked to the parent commit and corresponding tree object which is already linked to it's blob/tree object? 当我们执行git add时它会创建blob对象和树对象吗?当我们执行git commit ,提交对象链接到父提交和已经链接到它的blob / tree对象的相应树对象?

Or 要么

Does it just stores the info in index file (that something is changed and when we do git add it says ready for commit) and when we do git commit all the objects creation and linking happen between commit, tree, blob objects? 它只是将信息存储在索引文件中(某些内容已更改,当我们执行git时添加它表示准备提交),当我们执行git commit所有对象的创建和链接都发生在commit,tree,blob对象之间?

"Staging area" is convenience jargon for the most common and popular way to use the index. “临时区域”是使用索引的最常见和最流行的方式的便利术语。 Your first option, 你的第一个选择,

Does it create the blob object and tree object when we do git add and when we do git commit the commit object is linked to the parent commit and corresponding tree object which is already linked to it's blob/tree object? 当我们执行git add时它会创建blob对象和树对象吗?当我们执行git commit时,提交对象链接到父提交和已经链接到它的blob / tree对象的相应树对象?

has it almost exactly right: git add puts what you added in the repo, and git commit ties the commit object to the parent commit and the corresponding tree object - - - but that corresponding tree object isn't in the repo yet, git commit builds the tree (that ties pathnames to content) by consulting the index, which is exactly what it says it is: an index, tying pathnames to content. 它几乎完全正确: git add将您添加的内容放入repo中, git commit将提交对象git commit到父提交和相应的树对象 - - 但相应的树对象尚未在repo中, git commit通过查询索引来构建树(将路径名绑定到内容),这正是它所说的:索引,将路径名绑定到内容。

So, git checkout updates the index to point to the content it checked out at each checked-out path, and git add updates the index to point to the content it added for each added path. 因此, git checkout更新索引以指向它在每个签出路径中检出的内容, git add更新索引以指向它为每个添加的路径添加的内容。

So you can use this as a "staging area", git commit only cares what you've added, not what's in your worktree. 因此,您可以其用作“临时区域”, git commit只关心您添加的内容,而不是您工作树中的内容。 This is why git checkout , git reset , git commit and git add all have --patch options: there's what you checked out, what you've added, and what's in your worktree. 这就是为什么git checkoutgit resetgit commitgit add all都有--patch选项:你检查了什么,你添加了什么,以及你的工作树中有什么。 At any point it might be useful to see differences between any of those, or "take back" part of the changes you made, maybe because they belong in another commit or just need further work. 在任何时候,看到任何这些之间的差异,或“收回”您所做的更改的一部分可能是有用的,可能是因为它们属于另一个提交或只是需要进一步的工作。

The staging area is a file, generally contained in your Git directory, that stores information about what will go into your next commit. 暂存区域是一个文件,通常包含在您的Git目录中,用于存储有关下一次提交的内容的信息。 Its technical name in Git parlance is the index , but the phrase staging area works just as well. 它在Git用语中的技术名称是index ,但短语staging area可以正常工作。

To stage a file is simply to prepare it finely for a commit. stage文件只是为了提交准备就绪。 Git, with its index allows you to commit only certain parts of the changes you've done since the last commit. Git及其索引允许您仅提交自上次提交以来所做的更改的某些部分。 Say you're working on two features - one is finished, and one still needs some work done. 假设您正在开发两个功能 - 一个已完成,一个仍需要完成一些工作。 You'd like to make a commit and go home but wouldn't like to commit the parts of the second feature, which is not done yet. 你想做一个提交并回家,但不想提交第二个功能的部分,这还没有完成。 You stage the parts you know belong to the first feature, and commit. 您将您知道属于第一个特征的部分暂存,然后提交。 Now your commit is your project with the first feature done, while the second is still in work-in-progress in your working directory. 现在,您的提交是您完成第一个功能的项目,而第二个功能仍在您的工作目录中正在进行中。

git add adds your modified files to the queue to be committed later. git add将修改后的文件git add到队列中以便稍后提交。 Files are not committed 文件未提交

git commit commits the files that have been added and creates a new revision with a log... If you do not add any files, git will not commit anything. git commit提交已添加的文件并使用日志创建新版本...如果您不添加任何文件,git将不会提交任何内容。 You can combine both actions with git commit -a 您可以将这两个操作与git commit -a结合使用

git push pushes your changes to the remote repository. git push将您的更改git push送到远程存储库。

You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory. 您执行提交,它将文件保存在暂存区域中,并将该快照永久存储到您的Git目录中。 Read more info : https://git-scm.com/book/en/v2/Getting-Started-Git-Basics 阅读更多信息: https//git-scm.com/book/en/v2/Getting-Started-Git-Basics

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

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