SlideShare ist ein Scribd-Unternehmen logo
1 von 80
Downloaden Sie, um offline zu lesen
Git 是什麼?
  What is Git?
Git 是什麼

git
[git]

n.

飯桶﹐無用的人
版本控制系統

™  多人協同開發
 ™  每個人開發一個小功能


™  改錯了還有救
 ™  可回溯到之前版本
 ™  可知道是誰改爛的
源起

™  Linus Torvalds
    (Linux 的作者)

™  為了管理 Linux Kernel
    程式碼而開發
採用 Git 的專案

™  Android                    ™  jQuery

™  Linux Kernel               ™  Perl

™  Debian, Fedora, openSUSE   ™  Qt

™  Git                        ™  Ruby on Rails

™  Gnome                      ™  VLC

™  GIMP                       ™  Wine

™  GTK+                       ™  X.org Server

                               ™  x264
Git 的好處
       Why Git is better than X
http://zh-tw.whygitisbetterthanx.com/
優於其他管理系統
本機管理系統
本機管理系統
中央管理系統 (CVCS)
中央管理系統 (CVCS)
分散管理系統 (DVCS)
分散管理系統 (DVCS)
沒有網路也能工作

™  Git once, coding anywhere!

™  Branch 開不用錢

™  看 log 超快
適合超大量資料

™  操作速度超快

™  儲存的檔案很小

™  連 Linux Kernel 都 hold 得住
Branch 不用錢

™  開 branch 幾乎零成本

™  開 branch 改東西,不怕改爛主軸

™  切換 branch 很簡單

™  Git 的 merge 很聰明
Git 的運作概觀
   Git overview
關於版本




The Others’ Way
關於版本




The Git’s Way
Git 是這樣看待 commit 的
Git 是這樣看待 commit 的
一些用語

™  HEAD
   ™  指出目前位於哪個節點

™  origin
   ™  預設的原始 repo 名稱

™  master
   ™  預設的 branch 名稱

™  bare repo
   ™  分享的 repo,習慣以 ProjName.git 命名
支援協定

™  file://
    ™  本機檔案,例如用 Dropbox 架 repo

™  ssh://
    ™  安全,適合寫入

™  git://
    ™  效率好,但沒有認證機制,適合唯讀

™  http:// or https://
    ™  簡單,效率低,可突破防火牆
忽略規則

™  空目錄會被忽略
  ™  習慣放個 .gitkeep 在裡頭避免忽略

™  用 .gitignore 排除不需要的檔案
  ™    https://github.com/github/gitignore
  ™    放在 Working tree 的根目錄
  ™    記得也要 commit
  ™    能自動產生的東西都該排除
  ™    全域設定放在 ~/.gitignore
Git 常用指令
  Git commands
git config

™  使用者資訊,commit 時會用到
  ™  git config --global user.name “Your Name”
  ™  git config --global user.email “account@mail.address”
git config

™  讓終端機顯示上色
 ™  git config --global color.ui true
git config

™  For Linux & Mac
   ™  git config --global core.autocrlf input
   ™  git config --global core.safecrlf true

™  For Windows
   ™  git config --global core.autocrlf true
   ™  git config --global core.safecrlf true
git init

™  初始化 repo

™  建立 bare repo
   ™  git init --bare
git add

™  將新檔案加入追蹤

™  將修改過的檔案加入 stage

™  git add .
   ™  將所有檔案加入追蹤
   ™  常接在 git init 之後
git commit

™  提交 stage 裡的資料

™  git commit -m “Commit message”
git clone

™  複製一份 repo

™  從 bare repo 複製
   ™  git clone protocol://path/to/bare_repo.git

™  從現有 repo 建立 bare repo
   ™  git clone --bare <dir_name> <bare_dir_name>.git
git status

™  檢視目前狀態
git branch

™  列出或建立 branch

™  git branch <branch_name>

™  branch name 強烈建議用 [0-9A-Za-z_-.]
git tag

™  列出或建立 tag

™  tag name 強烈建議用 [0-9A-Za-z_-.]
git tag (cont.)

™  建立 tag
  ™  git tag <tag_name>
  ™  git push --tags

™  移除 tag
  ™  git tag -d <tag_name>
  ™  git push origin :refs/tags/<tag_name>
git checkout

™  切換到其他 branch

™  git checkout -b <branch_name> =
    git branch <branch_name> +
    git checkout <branch_name>
git stash

™  保存目前的工作環境

™  git stash apply --index <stash_name>
   ™  將保存的環境倒回來,包含 stage 的內容
git reset

™  重置 stage 的狀態

™  git reset HEAD <file_name>
   ™  重置單一檔案

™  git reset HEAD
   ™  重置所有檔案

™  git reset --hard HEAD
   ™  連 working tree 也重置
git revert

™  取消上個 commit

™  git revert HEAD
   ™  會建立一個新 commit
git fetch

™  將本機 repo 與遠端 repo 同步
git pull

™  將本機 repo 與遠端 repo 同步,並更新 working tree

™  git pull = git fetch + git merge
git push

™  推送本機 repo 資料到遠端 repo
git merge

™  合併資料到當前 branch
Git 工作流程
  Work with Git
工作流程
ref. http://progit.org/book/ch5-1.html
Centralized Workflow
       中央控管
      適合小型團隊
Integration-Manager Workflow
          整合式管理員
    適合網路多人協同專案,例如 GitHub.com
Dictator and Lieutenants Workflow
            司令官與副手
        適合超大專案,例如 Linux Kernel
分支模型
ref. http://nvie.com/posts/a-successful-git-branching-model/
master

™  一直存在的分支

™  記錄每個上線的版本

™  只有在推出新版時才會變動

™  所謂的穩定版(stable version)
develop

™  一直存在的分支

™  必須總是 build 得過

™  new feature 跟 enhancement 都在這裡

™  所謂的測試版(beta version)
feature

™  從 develop 分支出來

™  要 merge 回 develop

™  新增或修改功能時才會出現

™  功能完成就砍掉
release

™  從 develop 分支出來
™  要 merge 回 master,並且上 tag
™  要 merge 回 develop
™  管理者決定要 release 新版時才會建立
™  release 之後就砍掉
™  修改版本號、Release Note、ReadMe
™  最後測試並修正測試發現的 bug
hotfix

™  從 master 分支出來

™  要 merge 回 master,並且上 tag

™  要 merge 回 develop 或 release

™  緊急修正問題專用

™  修正之後就砍掉

™  修改版本號、Release Note、ReadMe
總結

™  不同 branch 有不同用途,不得混用

™  任何更動都要開 branch

™  除了 master 跟 develop 之外,完成任務就砍掉 branch
建議工作規範
  My proposal
時常同步

™  每天或每週一次

™  有備份才安心

™  習慣 Git 的操作

™  降低 merge 困難度
愛用 branch

™  開 branch 不用錢,所以任何變動都開 branch

™  不要在 master 或 develop 修改程式
詳細 commit

™  記得移除行尾空白

™  一次只 commit 一個主題

™  commit message 寫清楚
  ™  第一行:主旨,少於 50 字元
  ™  第二行:空白
  ™  第三行:詳情,每行少於 74 字元
關於檔案

™  避免不同平台產生亂碼
 ™  檔名只能用 ASCII 字元	
 ™  檔名不得使用可能非法字元,如 / ? < > *  : | ”
 ™  文字檔編碼一律用 UTF-8


™  避免不同軟體產生亂碼
 ™  文字檔內容一律用 ASCII 字元(即:不得用中文)
Git 工具
Git on Windows & Mac
安裝 Git

™  Mac
   ™  http://code.google.com/p/git-osx-installer/



™  Windows
   ™  http://code.google.com/p/msysgit/
跨平台工具
工程師的浪漫
Mac
SourceTree (Git/Hg)
http://itunes.apple.com/us/app/sourcetree-git-hg/id411678673?mt=12
GitX (L)
http://gitx.laullon.com/
Windows
TortoiseGit
http://code.google.com/p/tortoisegit/
SmartGit
 http://www.syntevo.com/smartgit/index.html
Cross-platform, free for non-commercial purpose.
EGit for Eclipse
  http://eclipse.org/egit/
Git 參考資料
  Git references
™  簡介
  ™  http://git-scm.com/
  ™  http://speakerdeck.com/u/dannvix/p/20111214-git-in-
      a-nutshell
  ™  http://www.slideshare.net/littlebtc/git-5528339



™  教學
  ™  http://progit.org/
  ™  http://marklodato.github.com/visual-git-guide/index-
      en.html
  ™  http://ihower.tw/blog/archives/category/git
™  其他
  ™  http://nvie.com/posts/a-successful-git-branching-
      model/
  ™  https://github.com/github/gitignore
  ™  http://zh-tw.whygitisbetterthanx.com/
  ™  http://people.debian.org.tw/~chihchun/2008/12/19/
      linus-torvalds-on-git/
你問,我…盡量答
   Q&A

Weitere ähnliche Inhalte

Was ist angesagt?

幸福快樂的完美結局
幸福快樂的完美結局幸福快樂的完美結局
幸福快樂的完美結局Anna Su
 
Git and git hub
Git and git hubGit and git hub
Git and git hub唯 李
 
Mercurial簡介與教學
Mercurial簡介與教學Mercurial簡介與教學
Mercurial簡介與教學芳本 林
 
連哈秋都懂的Git教學
連哈秋都懂的Git教學連哈秋都懂的Git教學
連哈秋都懂的Git教學hydai
 
Git 入門與實作
Git 入門與實作Git 入門與實作
Git 入門與實作奕浦 郭
 
初心者 Git 上手攻略
初心者 Git 上手攻略初心者 Git 上手攻略
初心者 Git 上手攻略Lucien Lee
 
Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀Wen-Tien Chang
 
寫給大家的 Git 教學
寫給大家的 Git 教學寫給大家的 Git 教學
寫給大家的 Git 教學littlebtc
 
Visual Studio 2015 與 Git 開發實戰
Visual Studio 2015 與 Git 開發實戰Visual Studio 2015 與 Git 開發實戰
Visual Studio 2015 與 Git 開發實戰Will Huang
 
A successful git branching model 導讀
A successful git branching model 導讀A successful git branching model 導讀
A successful git branching model 導讀Wen Liao
 
Git & Sourcetree 介紹
Git & Sourcetree 介紹Git & Sourcetree 介紹
Git & Sourcetree 介紹Adison wu
 
Git flow 與團隊合作
Git flow 與團隊合作Git flow 與團隊合作
Git flow 與團隊合作Bo-Yi Wu
 
Git與source tree 基礎教學
Git與source tree 基礎教學Git與source tree 基礎教學
Git與source tree 基礎教學Duncan Chen
 
git merge 與 rebase 的觀念與實務應用
git merge 與 rebase 的觀念與實務應用git merge 與 rebase 的觀念與實務應用
git merge 與 rebase 的觀念與實務應用Will Huang
 
Git 入门实战
Git 入门实战Git 入门实战
Git 入门实战icy leaf
 
Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹PingLun Liao
 

Was ist angesagt? (20)

幸福快樂的完美結局
幸福快樂的完美結局幸福快樂的完美結局
幸福快樂的完美結局
 
Git and git hub
Git and git hubGit and git hub
Git and git hub
 
Mercurial簡介與教學
Mercurial簡介與教學Mercurial簡介與教學
Mercurial簡介與教學
 
Git 版本控制 (使用教學)
Git 版本控制 (使用教學)Git 版本控制 (使用教學)
Git 版本控制 (使用教學)
 
連哈秋都懂的Git教學
連哈秋都懂的Git教學連哈秋都懂的Git教學
連哈秋都懂的Git教學
 
Git 入門與實作
Git 入門與實作Git 入門與實作
Git 入門與實作
 
Git由超淺入超深
Git由超淺入超深Git由超淺入超深
Git由超淺入超深
 
初心者 Git 上手攻略
初心者 Git 上手攻略初心者 Git 上手攻略
初心者 Git 上手攻略
 
Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀
 
寫給大家的 Git 教學
寫給大家的 Git 教學寫給大家的 Git 教學
寫給大家的 Git 教學
 
Visual Studio 2015 與 Git 開發實戰
Visual Studio 2015 與 Git 開發實戰Visual Studio 2015 與 Git 開發實戰
Visual Studio 2015 與 Git 開發實戰
 
A successful git branching model 導讀
A successful git branching model 導讀A successful git branching model 導讀
A successful git branching model 導讀
 
Git & Sourcetree 介紹
Git & Sourcetree 介紹Git & Sourcetree 介紹
Git & Sourcetree 介紹
 
Git 經驗分享
Git 經驗分享Git 經驗分享
Git 經驗分享
 
Git flow 與團隊合作
Git flow 與團隊合作Git flow 與團隊合作
Git flow 與團隊合作
 
Gitlab
GitlabGitlab
Gitlab
 
Git與source tree 基礎教學
Git與source tree 基礎教學Git與source tree 基礎教學
Git與source tree 基礎教學
 
git merge 與 rebase 的觀念與實務應用
git merge 與 rebase 的觀念與實務應用git merge 與 rebase 的觀念與實務應用
git merge 與 rebase 的觀念與實務應用
 
Git 入门实战
Git 入门实战Git 入门实战
Git 入门实战
 
Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹
 

Andere mochten auch

Getting Git Right
Getting Git RightGetting Git Right
Getting Git RightSven Peters
 
Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners HubSpot
 
Git 101 Presentation
Git 101 PresentationGit 101 Presentation
Git 101 PresentationScott Chacon
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHubJames Gray
 
Advanced Git
Advanced GitAdvanced Git
Advanced Gitsegv
 
Git 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGit 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGeoff Hoffman
 
Introduction to Git/Github - A beginner's guide
Introduction to Git/Github - A beginner's guideIntroduction to Git/Github - A beginner's guide
Introduction to Git/Github - A beginner's guideRohit Arora
 
Quick Introduction to git
Quick Introduction to gitQuick Introduction to git
Quick Introduction to gitJoel Krebs
 
Sys05 uso consapevole di git - beyond the basic
Sys05   uso consapevole di git - beyond the basicSys05   uso consapevole di git - beyond the basic
Sys05 uso consapevole di git - beyond the basicDotNetCampus
 
Introduzione a GIT - Laboratorio di Web Design 2014/15
Introduzione a GIT - Laboratorio di Web Design 2014/15Introduzione a GIT - Laboratorio di Web Design 2014/15
Introduzione a GIT - Laboratorio di Web Design 2014/15Giovanni Buffa
 
Linux Day 2015 Genova
Linux Day 2015 GenovaLinux Day 2015 Genova
Linux Day 2015 Genovamperrando
 

Andere mochten auch (20)

Getting Git Right
Getting Git RightGetting Git Right
Getting Git Right
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
Getting Git
Getting GitGetting Git
Getting Git
 
Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners
 
Git in a nutshell
Git in a nutshellGit in a nutshell
Git in a nutshell
 
Git 101 Presentation
Git 101 PresentationGit 101 Presentation
Git 101 Presentation
 
Git and Github
Git and GithubGit and Github
Git and Github
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
Advanced Git
Advanced GitAdvanced Git
Advanced Git
 
Git 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGit 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using Git
 
Introduction to Git/Github - A beginner's guide
Introduction to Git/Github - A beginner's guideIntroduction to Git/Github - A beginner's guide
Introduction to Git/Github - A beginner's guide
 
Quick Introduction to git
Quick Introduction to gitQuick Introduction to git
Quick Introduction to git
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
GitSlides
GitSlidesGitSlides
GitSlides
 
Sys05 uso consapevole di git - beyond the basic
Sys05   uso consapevole di git - beyond the basicSys05   uso consapevole di git - beyond the basic
Sys05 uso consapevole di git - beyond the basic
 
Introduzione a GIT - Laboratorio di Web Design 2014/15
Introduzione a GIT - Laboratorio di Web Design 2014/15Introduzione a GIT - Laboratorio di Web Design 2014/15
Introduzione a GIT - Laboratorio di Web Design 2014/15
 
GITT (part 1 of 2)
GITT (part 1 of 2)GITT (part 1 of 2)
GITT (part 1 of 2)
 
Git–SVN
Git–SVNGit–SVN
Git–SVN
 
Perchè Git?
Perchè Git?Perchè Git?
Perchè Git?
 
Linux Day 2015 Genova
Linux Day 2015 GenovaLinux Day 2015 Genova
Linux Day 2015 Genova
 

Ähnlich wie Git in a nutshell

Git Essence Tutorial
Git Essence TutorialGit Essence Tutorial
Git Essence TutorialHo Kim
 
First meetingwithgit
First meetingwithgitFirst meetingwithgit
First meetingwithgitRhythm Sun
 
Git使用入门
Git使用入门Git使用入门
Git使用入门dpf2e
 
Git 超簡單學習懶人包(軟體程式版本控管系統)
Git 超簡單學習懶人包(軟體程式版本控管系統)Git 超簡單學習懶人包(軟體程式版本控管系統)
Git 超簡單學習懶人包(軟體程式版本控管系統)flylon
 
Git+使用教程
Git+使用教程Git+使用教程
Git+使用教程gemron
 
Git &amp; git hub v1.2
Git &amp; git hub v1.2Git &amp; git hub v1.2
Git &amp; git hub v1.2Chris Chen
 
Git flow
Git flowGit flow
Git flowshaokun
 
Git 簡介(古時候的簡報備份)
Git 簡介(古時候的簡報備份)Git 簡介(古時候的簡報備份)
Git 簡介(古時候的簡報備份)Hsin-lin Cheng
 
Git 使用介绍
Git 使用介绍Git 使用介绍
Git 使用介绍medcl
 
Git内部培训文档
Git内部培训文档Git内部培训文档
Git内部培训文档superwen
 
Git & git flow
Git & git flowGit & git flow
Git & git flowAmo Wu
 
Git原理与实战 201607
Git原理与实战 201607Git原理与实战 201607
Git原理与实战 201607Charles Tang
 
Learning to Use Git | WeiYuan
Learning to Use Git | WeiYuanLearning to Use Git | WeiYuan
Learning to Use Git | WeiYuanWei-Yuan Chang
 
20170510 git 懶人包
20170510 git 懶人包20170510 git 懶人包
20170510 git 懶人包Chen-Ming Yang
 

Ähnlich wie Git in a nutshell (20)

Git Tutorial
Git TutorialGit Tutorial
Git Tutorial
 
Git Essence Tutorial
Git Essence TutorialGit Essence Tutorial
Git Essence Tutorial
 
First meetingwithgit
First meetingwithgitFirst meetingwithgit
First meetingwithgit
 
Git使用入门
Git使用入门Git使用入门
Git使用入门
 
Git 超簡單學習懶人包(軟體程式版本控管系統)
Git 超簡單學習懶人包(軟體程式版本控管系統)Git 超簡單學習懶人包(軟體程式版本控管系統)
Git 超簡單學習懶人包(軟體程式版本控管系統)
 
Git 教學
Git 教學Git 教學
Git 教學
 
Git+使用教程
Git+使用教程Git+使用教程
Git+使用教程
 
Git &amp; git hub v1.2
Git &amp; git hub v1.2Git &amp; git hub v1.2
Git &amp; git hub v1.2
 
Git flow
Git flowGit flow
Git flow
 
Git 簡介(古時候的簡報備份)
Git 簡介(古時候的簡報備份)Git 簡介(古時候的簡報備份)
Git 簡介(古時候的簡報備份)
 
Git 使用介绍
Git 使用介绍Git 使用介绍
Git 使用介绍
 
Git share
Git shareGit share
Git share
 
Git内部培训文档
Git内部培训文档Git内部培训文档
Git内部培训文档
 
Git & git flow
Git & git flowGit & git flow
Git & git flow
 
Git原理与实战 201607
Git原理与实战 201607Git原理与实战 201607
Git原理与实战 201607
 
Build Your Own Android Toolchain from scratch
Build Your Own Android Toolchain from scratchBuild Your Own Android Toolchain from scratch
Build Your Own Android Toolchain from scratch
 
Learning to Use Git | WeiYuan
Learning to Use Git | WeiYuanLearning to Use Git | WeiYuan
Learning to Use Git | WeiYuan
 
Git基础培训
Git基础培训Git基础培训
Git基础培训
 
20150313 ian git
20150313 ian git20150313 ian git
20150313 ian git
 
20170510 git 懶人包
20170510 git 懶人包20170510 git 懶人包
20170510 git 懶人包
 

Git in a nutshell