顯示廣告
隱藏 ✕
看板 tails
作者 tails (QQ)
標題 [教學] Git使用教學 Part 5 -- 補充資料2
時間 2012年03月13日 Tue. AM 01:53:10


因為今天有點懶得再繼續研究
所以畫了一點圖來解釋一下Git到底在搞什麼鬼 (第一次畫 有點爛Orz...
以下是以我個人理解後所畫的
如果有錯請多加指正O.Q




       [  按  →  開  始  ]






^L

指令區:                     │ 圖示區:
                             │
                             │
                             │
                             │
                             │
                             │
                             │
                             │
                             │
                             │
                             │
                             │
                             │
                             │
                             │
                             │
                             │
                             │
                             │
                             │
^L

指令區:                     │ 圖示區:
                             │  ╭─我是空間,我超強!───────────────╮
$ git init                   │  │                                                  │untracked files:
                             │  │                                                  │
                             │  │                                                  │
                             │  │                                                  │
                             │  │                                                  │
                             │  │                                                  │unstaged files:
                             │  │                                                  │
                             │  │                                                  │
                             │  │                                                  │
                             │  │                                                  │
                             │  │                                                  │staged files:
                             │  │                                                  │
                             │  │                        HEAD                      │
                             │  │                         ↓                       │
                             │  │                       master                     │
                             │  ╰─────────────────────────╯
                             │   init一個Git repository,它內容會是空的
                             │   因為是完全空白,status會特別跟你說是初始化狀態
                             │   這時理論上master是不知道在哪的,所以第一步必須要先建立節點
^L

指令區:                     │ 圖示區:
                             │  ╭─我是空間,我超強!───────────────╮
$ git init                   │  │                                                  │untracked files:
$ touch test                 │  │                                                  │ test
                             │  │                                                  │
                             │  │                                                  │
                             │  │                                                  │
                             │  │                                                  │unstaged files:
                             │  │                                                  │
                             │  │                                                  │
                             │  │                                                  │
                             │  │                                                  │
                             │  │                                                  │staged files:
                             │  │                                                  │
                             │  │                        HEAD                      │
                             │  │                         ↓                       │
                             │  │                       master                     │
                             │  ╰─────────────────────────╯
                             │    建立test檔後,新加入的檔案經比對後發現空間裡面沒此檔案
                             │    它會被列入untracked files裡面
                             │
^L

指令區:                     │ 圖示區:
                             │  ╭─我是空間,我超強!───────────────╮
$ git init                   │  │                                                  │untracked files:
$ touch test                 │  │                                                  │
$ git add test               │  │                                                  │
                             │  │                                                  │
                             │  │                                                  │
                             │  │                                                  │unstaged files:
                             │  │                                                  │
                             │  │                                                  │
                             │  │                                                  │
                             │  │                                                  │
                             │  │                                                  │staged files:
                             │  │                                                  │ test
                             │  │                        HEAD                      │
                             │  │                         ↓                       │
                             │  │                       master                     │
                             │  ╰─────────────────────────╯
                             │    檔案經add後會被列入stage狀態中,當然這時也隨時能刪除
                             │    再來就是等待commit
                             │
^L

指令區:                     │ 圖示區:
                             │  ╭─我是空間,我超強!───────────────╮
$ git init                   │  │                                                  │untracked files:
$ touch test                 │  │                                                  │
$ git add test               │  │                                                  │
$ git commit                 │  │                                                  │
                             │  │                                                  │
                             │  │                                                  │unstaged files:
                             │  │                                                  │
                             │  │                                                  │
                             │  │                                                  │
                             │  │                                                  │
                             │  │                        HEAD                      │staged files:
                             │  │                         ↓                       │
                             │  │                       master                     │
                             │  │                         ↓                       │
                             │  │                                                │
                             │  ╰─────────────────────────╯
                             │    commit後就多了一個節點,同時master也指向這個節點
                             │
                             │
^L

指令區:                     │ 圖示區:
                             │  ╭─我是空間,我超強!───────────────╮
$ git init                   │  │                                                  │untracked files:
$ touch test                 │  │                                                  │
$ git add test               │  │                                                  │
$ git commit                 │  │                                                  │
$ echo test > test           │  │                                                  │
                             │  │                                                  │unstaged files:
                             │  │                                                  │ test
                             │  │                                                  │
                             │  │                                                  │
                             │  │                                                  │
                             │  │                        HEAD                      │staged files:
                             │  │                         ↓                       │
                             │  │                       master                     │
                             │  │                         ↓                       │
                             │  │                         ○                       │
                             │  ╰─────────────────────────╯
                             │    修改了test後,因為已經是追縱清單了,所以是列入unstaged
                             │
                             │
^L

指令區:                     │ 圖示區:
                             │  ╭─我是空間,我超強!───────────────╮
$ git init                   │  │                                                  │untracked files:
$ touch test                 │  │                                                  │
$ git add test               │  │                                                  │
$ git commit                 │  │                                                  │
$ echo test > test           │  │                                                  │
$ git add test               │  │                                                  │unstaged files:
                             │  │                                                  │
                             │  │                                                  │
                             │  │                                                  │
                             │  │                                                  │
                             │  │                        HEAD                      │staged files:
                             │  │                         ↓                       │ test
                             │  │                       master                     │
                             │  │                         ↓                       │
                             │  │                         ○                       │
                             │  ╰─────────────────────────╯
                             │    一樣加入stage
                             │
                             │
^L

指令區:                     │ 圖示區:
                             │  ╭─我是空間,我超強!───────────────╮
$ git init                   │  │                                                  │untracked files:
$ touch test                 │  │                                                  │
$ git add test               │  │                                                  │
$ git commit                 │  │                                                  │
$ echo test > test           │  │                                                  │
$ git add test               │  │                                                  │unstaged files:
$ git commit                 │  │                                                  │
                             │  │                                                  │
                             │  │                        HEAD                      │
                             │  │                         ↓                       │
                             │  │                       master                     │staged files:
                             │  │                         ↓                       │
                             │  │                                                │
                             │  │                         ↓                       │
                             │  │                         ○                       │
                             │  ╰─────────────────────────╯
                             │    現在又多了一個節點,只是比剛剛節點多了修改的內容
                             │
                             │
^L

指令區:                     │ 圖示區:
                             │  ╭─我是空間,我超強!───────────────╮
$ git init                   │  │                                                  │untracked files:
$ touch test                 │  │                                                  │
$ git add test               │  │                                                  │
$ git commit                 │  │                                                  │
$ echo test > test           │  │                                                  │
$ git add test               │  │                                                  │unstaged files:
$ git commit                 │  │                                                  │
$ git tag v1.0               │  │                                                  │
                             │  │                        HEAD                      │
                             │  │                         ↓                       │
                             │  │                       master                     │staged files:
                             │  │                         ↓                       │
                             │  │                         ○← < v1.0 >            │
                             │  │                         ↓                       │
                             │  │                         ○                       │
                             │  ╰─────────────────────────╯
                             │    tag預設是幫目前的節點加
                             │    tag也跟branch一樣,會指向某個節點。
                             │    不一樣的是,tag是靜態,branch是動態
^L

指令區:                     │ 圖示區:
                             │  ╭─我是空間,我超強!───────────────╮
$ git init                   │  │                                                  │untracked files:
$ touch test                 │  │                                                  │
$ git add test               │  │                                                  │
$ git commit                 │  │                                                  │
$ echo test > test           │  │                                                  │
$ git add test               │  │                                                  │unstaged files:
$ git commit                 │  │                                                  │
$ git tag v1.0               │  │                                                  │
$ git branch slave           │  │                   HEAD                           │
                             │  │                    ↓                            │
                             │  │                  master    slave                 │staged files:
                             │  │                       ↘                       │
                             │  │                         ○← < v1.0 >            │
                             │  │                         ↓                       │
                             │  │                         ○                       │
                             │  ╰─────────────────────────╯
                             │    新增branch
                             │
                             │
^L

指令區:                     │ 圖示區:
                             │  ╭─我是空間,我超強!───────────────╮
$ git init                   │  │                                                  │untracked files:
$ touch test                 │  │                                                  │
$ git add test               │  │                                                  │
$ git commit                 │  │                                                  │
$ echo test > test           │  │                                                  │
$ git add test               │  │                                                  │unstaged files:
$ git commit                 │  │                                                  │
$ git tag v1.0               │  │                                                  │
$ git branch slave           │  │                            HEAD                  │
$ git checkout slave         │  │                             ↓                   │
                             │  │                  master    slave                 │staged files:
                             │  │                       ↘  ↙                     │
                             │  │                         ○← < v1.0 >            │
                             │  │                         ↓                       │
                             │  │                         ○                       │
                             │  ╰─────────────────────────╯
                             │    切換branch,其實就只是切換HEAD
                             │
                             │
^L

指令區:                     │ 圖示區:
                             │  ╭─我是空間,我超強!───────────────╮
$ git init                   │  │                                                  │untracked files:
$ touch test                 │  │                                                  │
$ git add test               │  │                                                  │
$ git commit                 │  │                                                  │
$ echo test > test           │  │                                                  │
$ git add test               │  │                                                  │unstaged files:
$ git commit                 │  │                            HEAD                  │
$ git tag v1.0               │  │                             ↓                   │
$ git branch slave           │  │                            slave                 │
$ git checkout slave         │  │                             ↓                   │
$ touch test2                │  │                  master                        │staged files:
$ git add test2              │  │                       ↘  ↙                     │
$ git commit                 │  │                         ○← < v1.0 >            │
                             │  │                         ↓                       │
                             │  │                         ○                       │
                             │  ╰─────────────────────────╯
                             │    在slave branch加入新的檔案並commit
                             │    這時可以發現,slave指的節點跟master的節點是不一樣的
                             │    表示master的節點其實只跟slave的節點差了一個commit的變動而已
^L

指令區:                     │ 圖示區:
                             │  ╭─我是空間,我超強!───────────────╮
$ git init                   │  │                                                  │untracked files:
$ touch test                 │  │                                                  │
$ git add test               │  │                                                  │
$ git commit                 │  │                                                  │
$ echo test > test           │  │                                                  │
$ git add test               │  │                                                  │unstaged files:
$ git commit                 │  │                    HEAD                          │
$ git tag v1.0               │  │                     ↓                           │
$ git branch slave           │  │                   master   slave                 │
$ git checkout slave         │  │                     ↓      ↓                   │
$ touch test2                │  │                           ○                   │staged files:
$ git add test2              │  │                       ↘  ↙                     │
$ git commit                 │  │                         ○← < v1.0 >            │
$ git checkout master        │  │                         ↓                       │
$ touch test3                │  │                         ○                       │
$ git add test3              │  ╰─────────────────────────╯
$ git commit                 │    切回master branch並新增檔案commit
                             │
                             │
^L

指令區:                     │ 圖示區:
                             │  ╭─我是空間,我超強!───────────────╮
$ git init                   │  │                                                  │untracked files:
$ touch test                 │  │                                                  │
$ git add test               │  │                                                  │
$ git commit                 │  │                                                  │
$ echo test > test           │  │                        HEAD                      │
$ git add test               │  │                         ↓                       │unstaged files:
$ git commit                 │  │                       master                     │
$ git tag v1.0               │  │                         ↓                       │
$ git branch slave           │  │                              slave             │
$ git checkout slave         │  │                       ↙  ↘  ↙                 │
$ touch test2                │  │                     ○      ○                   │staged files:
$ git add test2              │  │                       ↘  ↙                     │
$ git commit                 │  │                         ○← < v1.0 >            │
$ git checkout master        │  │                         ↓                       │
$ touch test3                │  │                         ○                       │
$ git add test2              │  ╰─────────────────────────╯
$ git commit                 │    把slave merge過來並commit
$ git merge slave            │    以圖來看的話,其實merge這個動作也會是個節點
                             │    會記錄著合併過程,如衝突發生的處理等
^L

以上大概就是前兩章教學的觀念圖解法
它的概念跟資料結構所學的link是幾乎一模一樣的
--
※ 作者: tails 時間: 2012-03-13 01:53:10
※ 編輯: tails 時間: 2012-03-13 05:49:20
※ 看板: tails 文章推薦值: 2 目前人氣: 0 累積人氣: 2102 
分享網址: 複製 已複製
( ̄︶ ̄)b Knuckles, d2wu550 說讚!
1樓 時間: 2012-03-13 04:24:56 (台灣)
  03-13 04:24 TW
可以把 -- 改成 ^L 會有翻頁效果
2樓 時間: 2012-03-13 05:11:53 (台灣)
  03-13 05:11 TW
XDDD
r)回覆 e)編輯 d)刪除 M)收藏 ^x)轉錄 同主題: =)首篇 [)上篇 ])下篇