接着上篇 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 LICENSEthis 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
时间: 2024-10-13 16:32:44