SlideShare a Scribd company logo
Short introduction to Git
Taka Wang
2016/04/20
2
Who use Git
• Git
• Qt
• Linux Kernel
• Ruby on Rails
• Perl
• Android
• Eclipse
• PostgreSQL
• Gnome
• Debian
• KDE
• X.org
3
Why Version Control
• 可以隨時復原修改,回到之前的版本
• 多⼈
人
協作時,不會把別
人
的東⻄蓋掉
• 保留修改歷史記錄,以供查詢
• 軟體發⾏時,可以
方
便管理不同版本
4
Version Control System
• 建⽴ Repository (儲存庫),
用
來保存程式碼
•
方
便散佈程式給團隊,有效率協同開發
• 記錄誰改變什麼、在什麼時候、因為什麼原因
• Branch(分⽀),可因不同情境分開開發
• Tag(標籤) 重要
里
程碑,以便參照
5
What’s in Repository
• 所有跑起來這個專案需要的東
西
– 所有原始碼、範例設計檔、⽂件等等
– 暫存檔、log 檔案、build files 等編譯後的產物 則不需
要存進 Repository
6
Centralized VCS
7
Why not Centralized
• svn 開分⽀和 merge 超痛苦,能避免開 branch 就避免開
branch
• svn 看 log 超痛苦,需要等待網路連線
• svn commit 或 checkout 超慢,主機放內網 常 commit ⼀半
中斷
8
Distributed VCS
Why Distributed
• 減輕負擔,
一
切變輕鬆
• 不再需要把
一
切完美才commit,請隨時commit 你的修改
• 每次commit零風險
10
Local development
• 集中式的 VCS 系統,沒網路就不能開發,無法 commit,無法
看 history log
– 坐
高
鐵, 坐
飛
機的時候
– 網路故障的時候
– 咖啡店沒有無線網路的時候
• 分散式 CSV 系統即使沒網路,照常可以 commit 和看
history log。
• 不
用
擔
心
server備份
11
Working Tree/Staging Area
在commit前復原修改
How
• 從無到有
•
日
常操作
• 分枝與合併
14
從無到有
• git init
– 從已有的資料夾,建立repository
• git clone
– 從已有的repository複製
15
日
常操作
• git add
– 將修改加到staging area,但是還沒commit
• git commit
– 只有commit到local的repo
• git log
– 顯
示
branch的修改
日
誌
16
日
常操作
• git pull
– 從遠端的repo抓取,並且嘗試merge進
自
己
的branch
• git push
– 將你
自
己
的branch與data合併
至
遠端的repo
17
分枝與合併
• git checkout
– 切到新的branch context
• git branch
– 列出,建立以及管理working context
• git merge
– 將branch context merge到你
目
前在使
用
的
• git tag
– 在
日
志中,標
示
目
前的修改是重要的
18
初始化過程
• git init
• git commit
• modify…
• modify….
• git commit
• git push
19
• 建立空repo
• 向repo添加檔案
• 提交修改
• 上傳到遠端repo
分枝操作過程
• git branch newfeature
• git checkout newfeature
• modify...
• git commit
• git checkout master
• git merge newfeature
20
• 建立newfeature branch
• 切換到這個分
支
• 提交
文
件(local)
• 切換到預設主線
• 合併newfeature到主線
Merge Conflict
• git status 看哪些檔案conflict
•
手
動編輯這些檔案,解決衝突
• 或者
用
git mergetool
工
具處理
• 解決後單檔,git add這些檔
• 解決全部檔後,git commit or git rebase --continue
• git reset HEAD --hard (放棄合併)
21
22

More Related Content

PDF
寫給大家的 Git 教學
PDF
Learning to Use Git | WeiYuan
PDF
Git in a nutshell
PDF
Git Tutorial
PDF
版本控制 使用Git & git hub
PPTX
工程師必備第一工具 - Git
PDF
Git簡介
PPTX
Git & git hub v1.2
寫給大家的 Git 教學
Learning to Use Git | WeiYuan
Git in a nutshell
Git Tutorial
版本控制 使用Git & git hub
工程師必備第一工具 - Git
Git簡介
Git & git hub v1.2

Similar to 20160420 - git intro (20)

PPTX
Introduction to Version Control System for Windows
PDF
Git and Github basic with SourceTree
ODP
Git 程式碼版本控制軟體介紹
PDF
Git Tutorial 教學
PDF
初心者 Git 上手攻略
PPTX
Git and git hub
PPTX
Git introduction
PPTX
Git初步入門
PDF
Git 簡介(古時候的簡報備份)
PPTX
Git
PDF
2010 07-29-version control use git
PDF
Intro to Git 投影片
ODP
Git 教學
PDF
Introduction to git
PDF
Git 版本控制系統 -- 從微觀到宏觀
PPT
Git 超簡單學習懶人包(軟體程式版本控管系統)
PPTX
Git基礎介紹
PPTX
大家應該都要會的工具 Git 從放棄到會用1-基礎篇
PDF
Git tutorial for windows user (給 Windows user 的 Git 教學)
PPTX
Github簡介
Introduction to Version Control System for Windows
Git and Github basic with SourceTree
Git 程式碼版本控制軟體介紹
Git Tutorial 教學
初心者 Git 上手攻略
Git and git hub
Git introduction
Git初步入門
Git 簡介(古時候的簡報備份)
Git
2010 07-29-version control use git
Intro to Git 投影片
Git 教學
Introduction to git
Git 版本控制系統 -- 從微觀到宏觀
Git 超簡單學習懶人包(軟體程式版本控管系統)
Git基礎介紹
大家應該都要會的工具 Git 從放棄到會用1-基礎篇
Git tutorial for windows user (給 Windows user 的 Git 教學)
Github簡介
Ad

More from Jamie (Taka) Wang (20)

PDF
20200606_insight_Ignition
PDF
20200727_Insight workstation
PDF
20200723_insight_release_plan
PDF
20210105_量產技轉
PDF
20200808自營電商平台策略討論
PDF
20200427_hardware
PDF
20200429_ec
PDF
20200607_insight_sync
PDF
20220113_product_day
PDF
20200429_software
PDF
20200602_insight_business
PDF
20200408_gen11_sequence_diagram
PDF
20190827_activity_diagram
PDF
20150722 - AGV
PDF
20161220 - microservice
PDF
20160217 - Overview of Vortex Intelligent Data Sharing Platform
PDF
20151111 - IoT Sync Up
PDF
20151207 - iot strategy
PDF
20141210 - Microservice Container
PDF
20161027 - edge part2
20200606_insight_Ignition
20200727_Insight workstation
20200723_insight_release_plan
20210105_量產技轉
20200808自營電商平台策略討論
20200427_hardware
20200429_ec
20200607_insight_sync
20220113_product_day
20200429_software
20200602_insight_business
20200408_gen11_sequence_diagram
20190827_activity_diagram
20150722 - AGV
20161220 - microservice
20160217 - Overview of Vortex Intelligent Data Sharing Platform
20151111 - IoT Sync Up
20151207 - iot strategy
20141210 - Microservice Container
20161027 - edge part2
Ad

20160420 - git intro

  • 1. Short introduction to Git Taka Wang 2016/04/20
  • 2. 2
  • 3. Who use Git • Git • Qt • Linux Kernel • Ruby on Rails • Perl • Android • Eclipse • PostgreSQL • Gnome • Debian • KDE • X.org 3
  • 4. Why Version Control • 可以隨時復原修改,回到之前的版本 • 多⼈ 人 協作時,不會把別 人 的東⻄蓋掉 • 保留修改歷史記錄,以供查詢 • 軟體發⾏時,可以 方 便管理不同版本 4
  • 5. Version Control System • 建⽴ Repository (儲存庫), 用 來保存程式碼 • 方 便散佈程式給團隊,有效率協同開發 • 記錄誰改變什麼、在什麼時候、因為什麼原因 • Branch(分⽀),可因不同情境分開開發 • Tag(標籤) 重要 里 程碑,以便參照 5
  • 6. What’s in Repository • 所有跑起來這個專案需要的東 西 – 所有原始碼、範例設計檔、⽂件等等 – 暫存檔、log 檔案、build files 等編譯後的產物 則不需 要存進 Repository 6
  • 8. Why not Centralized • svn 開分⽀和 merge 超痛苦,能避免開 branch 就避免開 branch • svn 看 log 超痛苦,需要等待網路連線 • svn commit 或 checkout 超慢,主機放內網 常 commit ⼀半 中斷 8
  • 10. Why Distributed • 減輕負擔, 一 切變輕鬆 • 不再需要把 一 切完美才commit,請隨時commit 你的修改 • 每次commit零風險 10
  • 11. Local development • 集中式的 VCS 系統,沒網路就不能開發,無法 commit,無法 看 history log – 坐 高 鐵, 坐 飛 機的時候 – 網路故障的時候 – 咖啡店沒有無線網路的時候 • 分散式 CSV 系統即使沒網路,照常可以 commit 和看 history log。 • 不 用 擔 心 server備份 11
  • 15. 從無到有 • git init – 從已有的資料夾,建立repository • git clone – 從已有的repository複製 15
  • 16. 日 常操作 • git add – 將修改加到staging area,但是還沒commit • git commit – 只有commit到local的repo • git log – 顯 示 branch的修改 日 誌 16
  • 17. 日 常操作 • git pull – 從遠端的repo抓取,並且嘗試merge進 自 己 的branch • git push – 將你 自 己 的branch與data合併 至 遠端的repo 17
  • 18. 分枝與合併 • git checkout – 切到新的branch context • git branch – 列出,建立以及管理working context • git merge – 將branch context merge到你 目 前在使 用 的 • git tag – 在 日 志中,標 示 目 前的修改是重要的 18
  • 19. 初始化過程 • git init • git commit • modify… • modify…. • git commit • git push 19 • 建立空repo • 向repo添加檔案 • 提交修改 • 上傳到遠端repo
  • 20. 分枝操作過程 • git branch newfeature • git checkout newfeature • modify... • git commit • git checkout master • git merge newfeature 20 • 建立newfeature branch • 切換到這個分 支 • 提交 文 件(local) • 切換到預設主線 • 合併newfeature到主線
  • 21. Merge Conflict • git status 看哪些檔案conflict • 手 動編輯這些檔案,解決衝突 • 或者 用 git mergetool 工 具處理 • 解決後單檔,git add這些檔 • 解決全部檔後,git commit or git rebase --continue • git reset HEAD --hard (放棄合併) 21
  • 22. 22