初始化一個新的 git project,首先要建立一個新資料夾 (my_project),進到資料夾並且執行 git init 指令
$ mkdir my_project
$ cd my_project
$ git init
從這裡我們可以看到,在 my_project/ 底下,多了一個 .git 的資料夾
其實 .git 就是一個版本控制的小資料庫,裡面放了所有關於這個 project 的資訊
這樣一個 git 的專案就已經初始化完成了
首先,我們先新增一個 hello_world.txt 的檔案,內容為一行字串 Hello World
git status 來檢視所有檔案的狀態$ git status

我們這裡可以看到,目前 hello_world.txt 的狀態為 Untracked files,表示這是一個全新的檔案
git add <file> 來告知 git,哪些是我們即將要提交(commit)的檔案現在要提交 hello_world.txt
$ git add hello_world.txt
$ git status

hello_world.txt 的狀態改變成綠色的 Changes to be committed
表示這個檔案已經 "準備好" 要被提交(commit)了
git commit 來提交一個 patch$ git commit
這時候會進入 vim 的文字編輯模式,編輯提交訊息(commit message)
git log 檢視提交的歷史訊息$ git log
使用 git log 來檢視之前的提交的歷史訊息
commit 是 git 幫我們自動產生的長度 40 字元的 Hash 值,並且保證 commit id 絕對不會重複,用來識別所有不同的 patch
Author 即為透過 git config 設定的 username 跟 email
下半部為提交訊息,包含標題及內容
這時候再做 git status 時會顯示
表示目前此目錄下,沒有發生任何的更動
git show 檢視 patch 的修改內容$ git show
使用 git show 來檢視最後一次提交的 patch 所修改的內容
從 git show 可以看出,這個 patch 新增了一個 hello_world.txt 的檔案,內容為 Hello World