Git工作区和暂存区

什么是工作区:就是我们平常可以看到的目录
版本库(Repository):在创建git仓库之后,此时文件夹下会自动生成一个.git目录,这个就是版本库,但不是工作区
暂存区:版本库中会生成很多东西,其中最重要的就是称为stage(或者叫index)的暂存区,还有Git为我们自动创建的第一个分支master,以及指向master的一个指针叫HEAD

例如:我们对已有的文件进行更改

Simple@Simple MINGW64 ~/Desktop/gitdir (master)
$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   test.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        learn.txt

no changes added to commit (use "git add" and/or "git commit -a")

此时,Git非常清楚地告诉我们,test.txt被修改了,而learn.txt还从来没有被添加过,所以它的状态是Untracked

这时,我们可以使用git add将两个文件都添加,可以再查看一下状态

Simple@Simple MINGW64 ~/Desktop/gitdir (master)
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   learn.txt
        modified:   test.txt

这时候,命令git add把修改的内容都放到了暂存区(Stage),此时再执行git commit就可以将暂存区的内容一次性提交到分支

Simple@Simple MINGW64 ~/Desktop/gitdir (master)
$ git commit -m "test"
[master 686c787] test
 2 files changed, 2 insertions(+), 1 deletion(-)
 create mode 100644 learn.txt

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值