git init 初始化倉(cāng)庫(kù)
$ mkdir Hello-Git
$ cd Hello-Git
$ git init
Initialized empty Git repository in /Users/william/git/Hello-GitHub/Hello-Git/.git/
git status 查看倉(cāng)庫(kù)的狀態(tài)
$ 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 向暫存區(qū)中添加文件
$ 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 保存?zhèn)}庫(kù)的歷史記錄
$ git commit -m "First commit"
[master (root-commit) e57ce85] First commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README.md
<small>如果希望記錄詳細(xì)信息,在使用 commit 指令時(shí),不加 -m 即可,注釋的通用寫(xiě)法是:</small>
- <small>第一行為簡(jiǎn)述</small>
- <small>第二行是留空</small>
- <small>第三行開(kāi)始寫(xiě)詳細(xì)描述,如修改原因,修改內(nèi)容等</small>
<small>如果希望中止提交,將提交信息留空,直接關(guān)閉編輯器即可</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 查看某個(gè)文件的改動(dòng)</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 后面不帶參數(shù),查看的是 <big>工作樹(shù)和暫存區(qū)的差別</big>,如果執(zhí)行了 git add 命令把工作樹(shù)的內(nèi)容添加到暫存區(qū)后,再執(zhí)行 diff 命令,將會(huì)看不到任何信息:
$ git add README.md
$ git diff
$
這個(gè)時(shí)候,需要執(zhí)行 git diff HEAD 命令查看 <big>工作樹(shù)與上次提交之間的差別</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>