More Related Content Similar to Git 入門與實作 (20) Git 入門與實作2. 關於此課程
• 共 2 + 1 天
• 現場操作 + 能動的例子
• 要做 回家作業
• 回答 昨日/作業 疑問
2
4. Git
• 源自 Linux 的 Command-line 程式
– 比較難入門
– 不怕,有各式圖形介面。
– 但是,整合 有賺有賠 有完整有缺漏,
仍須以 Command-line 為準。
• 這裡以圖形操作為主,指令為輔。
4
6. 01
安裝 Git Extentions
Command-line
Debian: apt-get install git
Windows: msysgit
http://git-scm.com/download/win
Git Extensions
1. 需 .NET Framework 4.0
(Windows 7 於 Windows Update 勾選即可)
2. Google “git ext” 就能找到載點
http://sourceforge.net/projects/gitextensions/
3. 某一步要勾些東西。
4. 其他就,下一步…
6
10. 02
設定 name 與 email
對應指令
git config --global user.name <name>
git config --global user.email <email>
操作
1. 填填
Git Extensions 其他設定,按 Repair。
10
11. Config – 三個地方
• 每個專案,可以套用不同設定。
• 自己使用,沒納入版本控制,不影響別人。
11
參數 作用範圍 Linux Windows
--system 整個系統 /etc/gitconfig C:Program FilesGitetcgitconfig
--global 各別使用者 ~/.gitconfig C:UserYiPo.gitconfig
(不加參數) 各別專案 .git/config (同左)
12. Config – core.autocrlf
幫你處理 Linux 與 Windows 間,換行方式的轉換。
12
core.autocrlf Checkout Commit
true Windows Linux
input - Linux
false - -
15. 版本庫哪來?
• 建立 (Init) 全新的版本庫
– 準備好你的資料夾
– 另外有一種 純的 (Bare) 版本庫
• 無工作目錄,供伺服器用,通常就命名為 “FooBar.git”。
• 複製 (Clone) 現有的版本庫
– 來源可以是 本機目錄、http、ssh、git。
明天就有 現有的版本庫 可以練習了,今天先建立全新的。
15
18. Staging Area
不要再爭辯 Staging Area 的好壞啦!
• Staging Area 裡保存的東西,才會被 Commit。
– 就當作是 SVN 裡,給檔案打勾勾。
– 只是 Staging Area 它記錄的是個狀態。
Working
Directory
Staging
Area Repositoryadd commit
18
19. 04
操作 Staging Area
對應指令
git add, git reset,
git checkout, git mv, git rm, …
操作
1. 點點滑鼠
Repository
add
Working
Directory
Staging
Area
19
21. .gitignore
• 下列物品不要進版本庫:
– 原始碼就能產生的檔案 (.o, .exe, .dll, …)
– 暫存檔 (.tmp)、日誌檔 (.log)
– 個人設定、密碼
• 編輯檔案 “.gitignore” ,一併納入版本控制。
• 各種現成的 .gitignore 設定:
github/gitignore (https://github.com/github/gitignore)
21
24. Push & Fetch/Pull
分散式 嘛 人人平等。
別人的版本庫:remote
• Push remote
branch to branch, 權限需要
• Fetch remote
成為 “remote/branch”
• Pull = Fetch + Merge
push
pull
24
25. Fetch vs Pull – nothing commit yet
Fetch
只抓資料下來
Pull
還做了 Merge
origin/master
master
origin/master master
25
26. Fetch vs Pull – something commited
Fetch
只抓資料下來
Pull
還做了 Merge
origin/master master
master
origin/master
能不能像 SVN 那樣
接著在後面 commit?
Rebase 26
30. Day 1 Questions
• Stage 個別檔案失敗…
– 應該要可以
• 我 Push 成功了嗎?
– 相信它,看 remote/branch 便是。
– 仍不放心,可以 Browse 純版本庫。
– 往後用 GitLab Server,有網頁可看。
• 為什麼有兩個 master?
– 應該是 Git Extensions 的問題
• 子錄目裡還可以有 .gitignore 嗎?可以
– 外面的會影響裡面的
30
31. 防止沒人發問的一頁
• 單獨 checkout 個別檔案、個別子目錄?不能
– 應該視專案為完整個體。
• 記錄空資料夾?不能
– .gitkeep 或 .gitignore。
• 曾經納入過版本庫的檔案,
就再也 .gitignore 不掉了?對,很怪…
31
36. Merge
• 於所在分支,做 Commit,將指定分支納入。
– 該切到哪個分支,指定哪個分支,要弄對。
• 萬一 Conflict !?
1. 處理 Conflict
2. 丟進 Staging Area 並 Commit
36
<<<<<<<
x=func();
=======
func(3.14);
>>>>>>>
x=func(3.14)
37. 10
Merge & 解 Conflict
對應指令
git merge <branch>
操作
1. 切換至對的 Branch
2. Commands > Merge brances…
(↓ 若發生 Conflict)
3. 處理 Conflict
4. 丟進 Staging Area 並 Commit
37
39. 延伸閱讀
• Git Reference (http://gitref.org/)
– 指令快速上手
• Pro Git (http://git-scm.com/book/)
– 完整詳盡的免費電子書
• git ready (http://gitready.com/)
– 單元式介紹
• Git 版本控制系統 (https://ihower.tw/git/)
– ihower 寫的書
39