git init 初始化仓库
$ mkdir Hello-Git
$ cd Hello-Git
$ git init
Initialized empty Git repository in /Users/william/git/Hello-GitHub/Hello-Git/.git/
git status 查看仓库的状态
$ touch README.md
$ git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
README.md
nothing added to commit but untracked files present (use "git add" to track)
git add 向暂存区中添加文件
$ git add README.md
$ git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: README.md
git commit 保存仓库的历史记录
$ git commit -m "First commit"
[master (root-commit) e57ce85] First commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README.md
<small>如果希望记录详细信息,在使用 commit 指令时,不加 -m 即可,注释的通用写法是:</small>
- <small>第一行为简述</small>
- <small>第二行是留空</small>
- <small>第三行开始写详细描述,如修改原因,修改内容等</small>
<small>如果希望中止提交,将提交信息留空,直接关闭编辑器即可</small>
git log 查看提交日志
$ git log
commit e57ce85ae7ce74318e7424e05bc508b06ea7c6dc
Author: JannyHo <fung.w.chan@hotmail.com>
Date: Tue May 16 11:00:38 2017 +0800
First commit
- <small>--pretty=short 只查看一行提交信息</small>
- <small>-p filename 查看某个文件的改动</small>
git diff 查看更改前后的差别
$ git diff
diff --git a/README.md b/README.md
index e69de29..ec80c56 100644
--- a/README.md
+++ b/README.md
@@ -0,0 +1 @@
+# Git 教程
- <small>如果 diff 后面不带参数,查看的是 <big>工作树和暂存区的差别</big>,如果执行了 git add 命令把工作树的内容添加到暂存区后,再执行 diff 命令,将会看不到任何信息:
$ git add README.md
$ git diff
$
这个时候,需要执行 git diff HEAD 命令查看 <big>工作树与上次提交之间的差别</big> :
$ git diff HEAD
diff --git a/README.md b/README.md
index e69de29..ec80c56 100644
--- a/README.md
+++ b/README.md
@@ -0,0 +1 @@
+# Git 教程
</small>