git index file之意(你和可能没有正确理解过)
来源:互联网 发布:淘宝售假违规扣48分 编辑:程序博客网 时间:2024/05/18 13:42
What’s The Deal With The Git Index?
Commands discussed in this section:
- git add
- git commit
- git ls-files
- git status
- git mv
- git rm
The git index defined in 2 sentences
The git “index” is where you place files you want committed to the git repository.
Before you “commit” (checkin) files to the git repository, you need to first place the files in the git “index”.
An index by any other name
The git index goes by many names. But they all refer to the same thing. Some of the names you may have heard:
- Index
- Cache
- Directory cache
- Current directory cache
- Staging area
- Staged files
Why so many names for the same thing? Good question! We don’t cover linguistics questions in this section, but you can be sure the answer would start with “For historical reasons…”
The Index Isn’t The Working Directory
The working directory is where you do your work: You add, remove, and modify files in the working directory.
You can type a command such as git status and git will tell you:
- What files have been added to the git index (for example by using the git add filename command).
- What files git notices that exist in the working directory, but aren’t in the git index.
- What files have different contents between the version in the git index and the version in the working directory.
The Index Isn’t The Git Repository
Files in the git index are files that git would commit to the git repository if you used the git commit command.
However, files in the git index don’t get committed to the repository until you use the git commit command.
The Index: Compared with Legacy VCS’s
Let’s say you have just created a new file named README. How do you add the file to your repository?
In a legacy Version Control System (VCS):
- You tell the VCS what file you want added to the repository (Perforce: p4 add README; Subversion: svn add README)
- Then tell the VCS to save the file to the repository (Perforce: p4 submit; Subversion: svn commit …)
Git behaves differently. With git, to add a new file to the git repository, you:
- Use “git add README”. This causes git to:
- Copy the contents of the README file to the git object store and store its contents as a blob.
- Record in the git index: Filename README and the hash of the README blob in the object store.
- Mark (remember) the README file in the user’s working directory is now “tracked”.
- Use “git commit” which takes the files that are referred to in the “git index” and saves them to the git repository.
Git Index Example
In the below example:
- A git session is shown in the upper right portion of the diagrams.
- The result of the session is shown in the lower right portion (words) and in the left portion (pictures).
- The most recent command typed is shown in a brown font
- The Session begins in a new, empty, directory immediately after a new git repository has been created (e.g. after “git init“).
You can click on the thumbnails in the lower left hand corner to choose which image to display.
You can click on the thumbnails in the lower left hand corner to choose which image to display.
A couple helpful index-related commands
A couple of git commands can be very helpful in showing you what files are in the index, whether or not the filenames in the index have been changed in the working directory, etc.
The git commands are:
- git status: Show what git determines are differences between the working directory, index and the most recent commit. For example:
- git ls-files: Show what files are in the git index
See What’s in the index? What’s Changed? for examples of the git status and git ls-files commands.
You can see examples of git diff which can show differences between the working directory, index, and repository.
Renaming and Removing files
To rename a file in the index and the working directory:
$ git mv README readme$ git ls-filesreadme$ git status# On branch master# Changes to be committed:# (use "git reset HEAD ..." to unstage)## renamed: README -> readme#
And to remove a file from the working directory and the index:
$ rm README$ git rm README
- git index file之意(你和可能没有正确理解过)
- 你可能没有见过的html标签
- Git 索引文件(index file)
- 有没有想过 你的数据分析方法可能已经过时?
- 有没有想过 你的数据分析方法可能已经过时?
- GIT中索引文件(index file)的作用
- 你有没有过?-------Day87
- SHOW INDEX 你用过吗???
- Git报错:index.lock File exists
- Git报错:index.lock File exists
- git error:index file smaller than expected
- git fatal: index file smaller than expected
- 你可能没用过的Linux命令
- 你可能没用过的Linux命令
- View 的Gone和Invisiable(你可能没想过的区别)
- View 的Gone和Invisiable(你可能没想过的区别)
- 不是没有可能,就看你能不能
- 无法访问。你可能没有权限使用网络资源。
- 【myeclipse】MyEclipse 中各种 libraries 的含义
- ECharts使用
- Android ActionBar应用实战,高仿微信主界面的设计
- android 多线程断点续传下载 三
- 【翻译】finalize方法到底要干嘛
- git index file之意(你和可能没有正确理解过)
- IOS 项目开发 必备的第三方类及需自己开发的第三方
- 安装PHP正解
- 使用宏的注意事项
- 编程小计算汇总(实时更新)
- 有符号int和无符号int的比较
- 坑1
- Python实现无重复数字的多位数全部输出
- 黑马程序员——OC语言------OC特有语法:分类、description、类对象、SEL