git add之后,stage中是否存储了多个文件? [英] Is there multiple files stored in the `stage` after `git add`?

查看:50
本文介绍了git add之后,stage中是否存储了多个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,在 git的每个操作后添加文件名" ,git会创建一个相应的 object ,并恢复指向该的指针 index 中的对象.

As far as I know,after each operation of git add "filename",the git will create an corresponding object,and restore a pointer to that object in the index.

这里是一个例子:

 touch a.txt 
 git add a.txt//version 1
 modify a.txt 
 git add a.txt//version 2

index 中是否存储了两个文件,分别对应于version1和version2?还是仅存在最新的version2?

Are there two files stored in the index,which corresponds to version1 and version2?Or just exist the newest version2?

是否会删除 index 中的version1,而仅恢复version2?

Will the version1 in index be deleted and only restore the version2?

推荐答案

的文档> git add 解释(强调是我的):

The documentation of git add explains (emphasis is mine):

说明

此命令使用在工作树中找到的当前内容更新索引,以准备为下一次提交暂存的内容. 它通常将现有路径的当前内容作为一个整体添加 ,但是通过某些选项,它也可以用于仅对工作树进行部分更改的内容来添加内容应用的文件,或删除工作树中不再存在的路径.

This command updates the index using the current content found in the working tree, to prepare the content staged for the next commit. It typically adds the current content of existing paths as a whole, but with some options it can also be used to add content with only part of the changes made to the working tree files applied, or remove paths that do not exist in the working tree anymore.

索引"保存工作树内容的快照 ,并且此快照被用作下一次提交的内容.因此,在对工作树进行任何更改之后,并且在运行commit命令之前,必须使用add命令将所有新文件或已修改的文件添加到索引中.

The "index" holds a snapshot of the content of the working tree, and it is this snapshot that is taken as the contents of the next commit. Thus after making any changes to the working tree, and before running the commit command, you must use the add command to add any new or modified files to the index.

在不深入了解实现细节的情况下,暂存区(也称为索引")保留当前工作树的副本.可以使用 git add git rm 命令.

Without digging into implementation details, the staging area (aka the "index") keeps a copy of the current working tree. The files created, modified or deleted in the working tree can be "added" to the index using the git add and git rm commands.

这样,用户可以准备下一次提交的内容.可以只提交工作树中操作的部分更改,而索引用于存储接下来要提交的内容.

This way the user prepares the content of the next commit. It is possible to commit only a part of the changes operated in the working tree and the index is used to store what will be committed next.

索引不包含版本.它仅包含每个文件的一个副本,即您使用上一个运行的最后一个 git add 命令添加的副本. 1 如果在将文件添加到索引后对其进行了修改,除非您在提交之前将文件再次添加到索引中,否则不会提交新的更改.

The index does not contain versions. It contains only one copy of each file, the one you added with the last git add command you ran.1 If you modify the file after you add it to the index, the new changes won't be committed unless you add the file to the index again before committing it.

1 索引也通过 git checkout git reset git merge 和其他Git命令进行更新但它们不在本讨论的范围之内.

1 The index is also updated by git checkout, git reset, git merge and other Git commands but they are not in the scope of this discussion.

这篇关于git add之后,stage中是否存储了多个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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