git 三个重要的状态

git 三个重要的状态

The Three States
Now, pay attention. This is the main thing to remember about Git if you want the rest of your learning process to go smoothly. Git has three main states that your files can reside in: committed, modified, and staged. Committed means that the data is safely stored in your local database. Modified means that you have changed the file but have not committed it to your database yet. Staged means that you have marked a modified file in its current version to go into your next commit snapshot.
翻译:
现在请注意,假如你希望git接下来的学习更轻松更顺利,那么你必须记住下面的事情.
Git 有三个重要的状态:
1. 提交的;
2. 修改的(未commit);
3. 缓存的
提交:表示你修改的数据已经安全的保存到了本地仓库;
修改:你修改了文件,但是还没有提交到本地仓库;
缓存:表示你已经标记了修改的文件作为下次commit的一部分,
如果你不标记,那么下次commit的时候,就不会提交这个文件.

This leads us to the three main sections of a Git project: the Git directory, the working directory, and the staging area.
翻译:git项目分为三个主要的部分:
1. git本地仓库;
2. 工作区;
3. 缓存区
git的三种状态

The Git directory is where Git stores the metadata and object database for your project. This is the most important part of Git, and it is what is copied when you clone a repository from another computer.

The working directory is a single checkout of one version of the project. These files are pulled out of the compressed database in the Git directory and placed on disk for you to use or modify.

The staging area is a file, generally contained in your Git directory, that stores information about what will go into your next commit. It’s sometimes referred to as the “index”, but it’s also common to refer to it as the staging area.

The basic Git workflow goes something like this:

You modify files in your working directory.

You stage the files, adding snapshots of them to your staging area.

You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.

If a particular version of a file is in the Git directory, it’s considered committed. If it has been modified and was added to the staging area, it is staged. And if it was changed since it was checked out but has not been staged, it is modified. In Git Basics, you’ll learn more about these states and how you can either take advantage of them or skip the staged part entirely.

工作区:就是你在电脑上看到的目录,比如目录下testgit里的文件(.git隐藏目录版本库除外)。或者以后需要再新建的目录文件等等都属于工作区范畴。

  版本库(Repository):工作区有一个隐藏目录.git,这个不属于工作区,这是版本库。其中版本库里面存了很多东西,其中最重要的就是stage(暂存区),还有Git为我们自动创建了第一个分支master,以及指向master的一个指针HEAD。

我们前面说过使用Git提交文件到版本库有两步:

第一步:是使用 git add 把文件添加进去,实际上就是把文件添加到暂存区。

第二步:使用git commit提交更改,实际上就是把暂存区的所有内容提交到当前分支上。

我们结合git的常用操作来体会下git的三个状态

git checkout –

git checkout – 实际上就是把修改的文件恢复到本地仓库的状态

git reset

git reset 把commit的内容回滚到本地仓库上次提交的状态

git add

git add就是把工作区的文件添加到缓存区
git tree

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值