Git暂存区只是一个索引? [英] Is the Git staging area just an index?

查看:87
本文介绍了Git暂存区只是一个索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Git说,暂存区只是一个列表或索引,它指出在完成 git commit 时将提交哪些文件,现在名称 index 通常被称为暂存区域。 但是,如果我们修改 foo.txt ,它已经是repo的一部分,并且使用 git add foo.txt 来放置它,然后再次修改文件,现在该文件是staged和modified(如 git status 中所见),如果我们提交,stage版本将进入提交。第二次编辑不会进入。



那么,如果第一次编辑只是一个索引,那么暂存区如何跟踪第一次编辑?的文件?

解决方案

索引是您的工作目录的视图,可供提交。它可以被看作是预先提交的状态,并不像文件列表那么简单。当您执行 git add 时,文件(包含更改)将添加到索引中,只有在添加更新后,才能查看新更改。


The book Pro Git says that the staging area was just an list, or index, that says which files will be committed when a git commit is done, and now the name index is more commonly known as the "staging area".

But if we modify the file foo.txt that is already part of the repo, and use git add foo.txt to stage it, and modify the file again, now the file is both "staged" and "modified" (as seen in git status), and if we commit, the "staged" version will go into the commit. The second edit won't go in.

So how can the "staging area" keep track of what the first edit was if it is just an index -- a list of files?

解决方案

Index is a view of your working directory that is ready for commit. It can be seen as a pre-commit state and is not as simple as a "list of files". When you do git add, the file (with the change) is added to the index and the newer changes will not be see until you add them too.

这篇关于Git暂存区只是一个索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆