码迷,mamicode.com
首页 > 其他好文 > 详细

git的使用(二)

时间:2016-03-27 01:16:14      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:

接着上篇 git的使用(一) http://www.cnblogs.com/horizonli/p/5323363.html

6.工作区和暂存区(中转站)

  工作区(Working Directory)

  就是你在电脑里能看到的目录:

  技术分享

  版本库(Repository)

  工作区有一个隐藏目录.git,是Git的版本库。

  技术分享

--------------------------------------------------------------------------------

  Git的版本库里存了很多东西,其中最重要的就是称为stage(或者叫index)的暂存区(中转站),

  还有Git为我们自动创建的第一个分支master,以及指向master的一个指针叫HEAD

  技术分享

          技术分享

[实践出真知]

 readme.txt增加一句:Git has a mutable index called stage.  并增加一个文本文件LICENSE
$ cat readme.txt
Git is a distributed  version control system.
Git is free software distributed under the GPL.
Git has a mutable index called stage.

$ echo "this is a text" >> LICENSE
$ cat LICENSE
this is a text

结果应该是在工作区 更改了readme.txt,并增加了一个文本文件LICENSE

$ 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:   readme.txt                                            #表示此文件被修改,未被提交到中转站(暂存区)

Untracked files:                                                          #Untracked表示此文件放置在工作区未提交
  (use "git add <file>..." to include in what will be committed)

        LICENSE

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

两次add,将readme.txt和LICENSE加入到暂存区

$ git add readme.txt


$ git add LICENSE
warning: LF will be replaced by CRLF in LICENSE.
The file will have its original line endings in your working directory.

$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   LICENSE
        modified:   readme.txt

技术分享

---------------------------------------------------------------------------

从中转站(暂存区)提交代码到.git 仓库

$ git commit -m "understand how stage/index works"                   #从中转站(暂存区)提交代码到.git 仓库
[master 3c8d3b2] understand how stage/index works
warning: LF will be replaced by CRLF in LICENSE.
The file will have its original line endings in your working directory.
 2 files changed, 2 insertions(+)
 create mode 100644 LICENSE


$ git status                                                         #验证是否都提交,工作区是否clean
On branch master
nothing to commit, working directory clean

技术分享

 
 

git的使用(二)

标签:

原文地址:http://www.cnblogs.com/horizonli/p/5324513.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!