$ pwd
/c/Users/Administrator
Administrator@YOUNG-PC MINGW64 ~
$ mkdir HelloWorld
Administrator@YOUNG-PC MINGW64 ~
$ cd HelloWorld/
Administrator@YOUNG-PC MINGW64 ~/HelloWorld
$ ls
Administrator@YOUNG-PC MINGW64 ~/HelloWorld
#初始化一个仓库,要进行版本管理,必须先初始化仓库
$ git init
Initialized empty Git repository in C:/Users/Administrator/HelloWorld/.git/
#执行完上面的命令后,下方提示的字符也发生了变化
$ ls -la
total 28
drwxr-xr-x 1 Administrator 1971210 三月 912:03 ./
drwxr-xr-x 1 Administrator 1971210 三月 912:03 ../
drwxr-xr-x 1 Administrator 1971210 三月 912:03 .git/
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
#这个文件下面的存储着管理当前目录所需的数据仓库
$ cd .git
Administrator@YOUNG-PC MINGW64 ~/HelloWorld/.git (GIT_DIR!)
$ ls
config description HEAD hooks/ info/ objects/ refs/
Administrator@YOUNG-PC MINGW64 ~/HelloWorld/.git (GIT_DIR!)
# 这个地方不能用git命令,必须返回上一级目录
$ git status
fatal: This operation must be run in a work tree
Administrator@YOUNG-PC MINGW64 ~/HelloWorld/.git (GIT_DIR!)
$ cd ..
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
$ pwd
/c/Users/Administrator/HelloWorld
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
$ ls
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
#查看仓库状态
$ git status
On branch master
Initial commit
nothing to commit (create/copy files and use "git add" to track)
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
$ touch READM.md
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
$ git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
READM.md
nothing added to commit but untracked files present (use "git add" to track)
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
#git add 想仓库中添加文件,下面的结果显示了我们再master分支下,如果只是单纯的创建了一个文件,并不会被加入git仓库的版本管理对象中,因此用git status 查看的话显示Untracked files,git add命令使之加入到缓存中,缓存是提交之前的一个临时区域
$ git add READM.md
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
$ git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: READM.md
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
#git commit 保存仓库的历史记录,,如果不加入-m,及后面的注释内容,则自动回出现vi编辑器,让你补充注释。#终止提交 ,将提交信息留空,直接关闭编辑器,提交会自动终止。
$ git commit -m "Frist commit"
[master (root-commit) 05791aa] Frist commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 READM.md
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
#提交完成后查看,状态,说明已经提交了。
$ git commit
On branch master
nothing to commit, working directory clean
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
#看下日志,记录了提交前后信息
$ git log
commit 05791aaa9acdcc8420ae8e61827ee1f41fbb45ff
Author: Thinker young <x695@qq.com>
Date: Wed Mar 920:06:282016 +0800
Frist commit
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
$
#优化显示信息
$ git log --pretty=short
commit 05791aaa9acdcc8420ae8e61827ee1f41fbb45ff
Author: Thinker young <x695@qq.com>
Frist commit
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
#显示前后差别
$ git log -p
commit 05791aaa9acdcc8420ae8e61827ee1f41fbb45ff
Author: Thinker young <x695@qq.com>
Date: Wed Mar 920:06:282016 +0800
Frist commit
diff --git a/READM.md b/READM.md
new file mode 100644
index 0000000..e69de29
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
$ git log -p READM.md
commit 05791aaa9acdcc8420ae8e61827ee1f41fbb45ff
Author: Thinker young <x695@qq.com>
Date: Wed Mar 920:06:282016 +0800
Frist commit
diff --git a/READM.md b/READM.md
new file mode 100644
index 0000000..e69de29
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
#查看前后差别
$ vi READM.md
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
$ git diff
diff --git a/READM.md b/READM.md
index e578ace..1e0b872 100644
--- a/READM.md
+++ b/READM.md
@@ -1 +1,2 @@
hello world !
+#get some diff
warning: LF will be replaced by CRLF in READM.md.
The file will have its original line endings in your working directory.
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
查看工作数树和最新提交的差别
#如果不加入head,则啥也不会显示
$ git diff
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
#加入head后,可以看本次提交和上次提交之间的差别
$ git diff HEAD
diff --git a/READM.md b/READM.md
index e69de29..1e0b872 100644
--- a/READM.md
+++ b/READM.md
@@ -0,0 +1,2 @@
+hello world !
+#get some diff
warning: LF will be replaced by CRLF in READM.md.
The file will have its original line endings in your working directory.
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
$ git commit -m "Add index"
[master warning: LF will be replaced by CRLF in READM.md.
The file will have its original line endings in your working directory.
478c9d6] Add index
warning: LF will be replaced by CRLF in READM.md.
The file will have its original line endings in your working directory.
1 file changed, 2 insertions(+)
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
#看下日志,查询到了第二个提交
$ git log
commit 478c9d6a50b3d44e3c57d534b899242e2dbc2a8a
Author: Thinker young <x695@qq.com>
Date: Wed Mar 920:29:282016 +0800
Add index
commit 05791aaa9acdcc8420ae8e61827ee1f41fbb45ff
Author: Thinker young <x695@qq.com>
Date: Wed Mar 920:06:282016 +0800
Frist commit
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
$