git 三个重要的状态

本文深入讲解Git中的三个核心状态:提交的、修改的和缓存的,并解释它们如何影响日常的工作流程。通过git的常用操作如checkout、reset及add等命令帮助理解这些状态的变化。

 

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.

我们结合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、付费专栏及课程。

余额充值