一、名词解释
Workspace
(工作区) : 本地的工作目录Index/Stage
(暂存区) : 工作区和本地仓库的中专站Local Repository
(本地仓库) : 本地的版本管理仓库Remote Repository
(远程仓库) : 远程热版本管理仓库
二、工作流程
1. 本地版本管理(查看演示)
牵扯到 workspace
、index/stage
和 local repository
三者的交互
workspace
⇒ \Rightarrow ⇒index/Stage
:git add
将文件添加到暂存区中workspace
⇐ \Leftarrow ⇐index/Stage
:git checkout
用暂存区的(所有)文件替换工作区中的文件,该操作会丢失被替换的文件自上一次git add
到现在的所有修改(不可逆,丢了就没了,回不去了)index/stage
⇒ \Rightarrow ⇒(local) repository
:git commit
将暂存区的所有文件提交到本地仓库中,形成一个版本workspace
⇐ \Leftarrow ⇐local repository
:git checkout HEAD
用HEAD
指向的分支中的(所有)文件替换工作区的文件,相当于回到一个特定的版本,该操作会丢失工作区所有文件相对于该版本的修改(不可逆,丢了就没了,回不去了)git merge <branch>
合并branch
分支到当前分支,在 git 分支中介绍
2. 远程服务器交互(查看演示)
牵扯到 workspace
、local repository
和 remote repository
三者的交互
repository
⇒ \Rightarrow ⇒remote
:git push
推送本地仓库到远程仓库中repository
⇐ \Leftarrow ⇐remote
:git clone
: 克隆远程仓库中的项目(所有信息)到本地仓库中git fetch
: 获取远程仓库的分支到本地仓库中(配合git merge
使用)
workspace
⇐ \Leftarrow ⇐remote
:git pull
获取远程仓库的分支并合并到本地分支中,相当于git fetch
+git merge
三、建立本地仓库
# create a new workspace dir
$ mkdir <dir-name>
# enter it
$ cd <dir-name>
# create a local repository
$ git init
Initialized empty Git repository in E:/document/git-test/.git/
# .git folder includes all the info of local repository
# view the newly generated.git folder (hidden by default, using -a)
$ ls -a
./ ../ .git/
# enter .git folder
$ cd .git
# view all the files
$ ls -l
total 7
-rw-r--r-- 1 red1y 197609 23 Jun 15 18:51 HEAD
-rw-r--r-- 1 red1y 197609 130 Jun 15 18:51 config
-rw-r--r-- 1 red1y 197609 73 Jun 15 18:51 description
drwxr-xr-x 1 red1y 197609 0 Jun 15 18:51 hooks/
drwxr-xr-x 1 red1y 197609 0 Jun 15 18:51 info/
drwxr-xr-x 1 red1y 197609 0 Jun 15 18:51 objects/
drwxr-xr-x 1 red1y 197609 0 Jun 15 18:51 refs/
# HEAD 指向当前分支的游标
$ cat HEAD
ref: refs/heads/master
objects/
存储了所有版本的对象refs/
存储了所有分支、版本的标识,标签
四、删除本地仓库
rm -rf .git
: 直接删除 .git
文件夹即可