SlideShare a Scribd company logo
1 of 9
Git 簡易教學




           姚芳德
Host Rep

                         Branch A




          Local Rep      Local Rep   Local Rep

          Branch A       Branch A    Branch A

          Branch A       Branch B    Branch B
             #2
          Branch B       Branch C    Branch C

                                     Branch D




Rep = Repository (知識庫)
Branches are cheap and easy, so this is a good
way to try something out。 -Linus Torvalds
本地端Git 流程

                       提交
   加入檔案      加上註解
                      COMMIT


將CODE上傳至HOST


   Commit至             Master
             HOST審核
    Master             更新
Git 增加檔案
•git add . # 先將資料先暫存到預傳區
•git add filename
• git add modify-file #
  修改過的檔案, 也要 add. (不然 commit 要加上 -a 的參數)
•git add -u # 只加修改過的檔案, 新增的檔案不加入.
•git add -i # 進入互動模式

Git 提交檔案
•git commit
•git commit -m 'commit message'
•git commit -a -m 'commit -message' #
 將所有修改過得檔案都 commit, 但是 新增的檔案 還是得要先 add.
•git commit -a -v # -v
 可以看到檔案哪些內容有被更改, -a 把所有修改的檔案都 commit
Git 增加分支
•git branch # 列出目前有多少 branch
•git branch new-branch #
 產生新的 branch (名稱: new-branch), 若沒有特別指定, 會由目
前所在的 branch / master 直接複製一份.
•git branch new-branch master #
 由 master 產生新的 branch(new-branch)
•git branch new-branch v1 # 由 tag(v1) 產生新的 branch(new-
branch)
•git branch -d new-branch # 刪除 new-branch
•git branch -D new-branch # 強制刪除 new-branch
•git checkout -b new-branch test #
 產生新的 branch, 並同時切換過去 new-branch
•# 與 remote repository 有關
•git branch -r # 列出所有 Repository branch
•git branch -a # 列出所有 branch
Git 切換分支
•git checkout branch-name # 切換到 branch-name
•git checkout master # 切換到 master
•git checkout -b new-branch master #
 從 master 建立新的 new-branch, 並同時切換過去 new-branch
•git checkout -b newbranch #
  由現在的環境為基礎, 建立新的 branch
•git checkout -b newbranch origin #
  於 origin 的基礎, 建立新的 branch
•git checkout filename # 還原檔案到 Repository 狀態
•git checkout HEAD . #
 將所有檔案都 checkout 出來(最後一次 commit 的版本), 注意, 若有
修改的檔案都會被還原到上一版. (git checkout -f 亦可)
•git checkout xxxx . # 將所有檔案都 checkout 出來(xxxx commit 的
版本, xxxx 是 commit 的編號前四碼), 注意, 若有修改的檔案都會被
還原到上一版.
•git checkout -- * # 恢復到上一次 Commit 的狀態(* 改成檔名, 就可
Git 合併分支
•git merge
•git merge master
•git merge new-branch
Git 觀看差異
•git diff master # 與 Master 有哪些資料不同
•git diff --cached # 比較 staging area 跟本來的 Repository
•git diff tag1 tag2 # tag1, 與 tag2 的 diff
•git diff tag1:file1 tag2:file2 # tag1, 與 tag2 的 file1, file2 的 diff
•git diff # 比較 目前位置 與 staging area
•git diff --cached # 比較 staging area 與 Repository 差異
•git diff HEAD # 比較目前位置 與 Repository 差別
•git diff new-branch # 比較目前位置 與 branch(new-branch) 的
差別
•git diff --stat

More Related Content

What's hot

版本控制 使用Git & git hub
版本控制   使用Git & git hub版本控制   使用Git & git hub
版本控制 使用Git & git hub維佋 唐
 
Git and git hub
Git and git hubGit and git hub
Git and git hub唯 李
 
SITCON Camp 2017 Telepot
SITCON Camp 2017 TelepotSITCON Camp 2017 Telepot
SITCON Camp 2017 Telepot鈵斯 倪
 
Grpc + python.key
Grpc + python.keyGrpc + python.key
Grpc + python.keyAndy Dai
 
Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹PingLun Liao
 
Git tutorial for windows user (給 Windows user 的 Git 教學)
Git tutorial for windows user (給 Windows user 的 Git 教學)Git tutorial for windows user (給 Windows user 的 Git 教學)
Git tutorial for windows user (給 Windows user 的 Git 教學)Cloud Tu
 
Mercurial簡介與教學
Mercurial簡介與教學Mercurial簡介與教學
Mercurial簡介與教學芳本 林
 
Git 使用介绍
Git 使用介绍Git 使用介绍
Git 使用介绍medcl
 

What's hot (11)

Git 版本控制 (使用教學)
Git 版本控制 (使用教學)Git 版本控制 (使用教學)
Git 版本控制 (使用教學)
 
版本控制 使用Git & git hub
版本控制   使用Git & git hub版本控制   使用Git & git hub
版本控制 使用Git & git hub
 
Git and git hub
Git and git hubGit and git hub
Git and git hub
 
SITCON Camp 2017 Telepot
SITCON Camp 2017 TelepotSITCON Camp 2017 Telepot
SITCON Camp 2017 Telepot
 
Grpc + python.key
Grpc + python.keyGrpc + python.key
Grpc + python.key
 
Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹
 
Git rebase -i
Git rebase -iGit rebase -i
Git rebase -i
 
Git tutorial for windows user (給 Windows user 的 Git 教學)
Git tutorial for windows user (給 Windows user 的 Git 教學)Git tutorial for windows user (給 Windows user 的 Git 教學)
Git tutorial for windows user (給 Windows user 的 Git 教學)
 
Git Tutorial 教學
Git Tutorial 教學Git Tutorial 教學
Git Tutorial 教學
 
Mercurial簡介與教學
Mercurial簡介與教學Mercurial簡介與教學
Mercurial簡介與教學
 
Git 使用介绍
Git 使用介绍Git 使用介绍
Git 使用介绍
 

Viewers also liked

2012 0521 雲端產業介紹 簡報
2012 0521 雲端產業介紹  簡報2012 0521 雲端產業介紹  簡報
2012 0521 雲端產業介紹 簡報Sitg Yao
 
2011 0616 老闆要我來報告
2011 0616 老闆要我來報告2011 0616 老闆要我來報告
2011 0616 老闆要我來報告Sitg Yao
 
2012 雲端產業介紹
2012 雲端產業介紹2012 雲端產業介紹
2012 雲端產業介紹Sitg Yao
 
Azure overview for it pros
Azure overview for it prosAzure overview for it pros
Azure overview for it prosSitg Yao
 
111102 dicom viewer_softwareintro
111102 dicom viewer_softwareintro111102 dicom viewer_softwareintro
111102 dicom viewer_softwareintroSitg Yao
 
Vim 由淺入淺
Vim 由淺入淺Vim 由淺入淺
Vim 由淺入淺hydai
 

Viewers also liked (6)

2012 0521 雲端產業介紹 簡報
2012 0521 雲端產業介紹  簡報2012 0521 雲端產業介紹  簡報
2012 0521 雲端產業介紹 簡報
 
2011 0616 老闆要我來報告
2011 0616 老闆要我來報告2011 0616 老闆要我來報告
2011 0616 老闆要我來報告
 
2012 雲端產業介紹
2012 雲端產業介紹2012 雲端產業介紹
2012 雲端產業介紹
 
Azure overview for it pros
Azure overview for it prosAzure overview for it pros
Azure overview for it pros
 
111102 dicom viewer_softwareintro
111102 dicom viewer_softwareintro111102 dicom viewer_softwareintro
111102 dicom viewer_softwareintro
 
Vim 由淺入淺
Vim 由淺入淺Vim 由淺入淺
Vim 由淺入淺
 

Similar to Git教學

Git 入门实战
Git 入门实战Git 入门实战
Git 入门实战icy leaf
 
Learn git
Learn gitLearn git
Learn git甘 李
 
Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀Wen-Tien Chang
 
Git 超簡單學習懶人包(軟體程式版本控管系統)
Git 超簡單學習懶人包(軟體程式版本控管系統)Git 超簡單學習懶人包(軟體程式版本控管系統)
Git 超簡單學習懶人包(軟體程式版本控管系統)flylon
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to gitBo-Yi Wu
 
Github简介及实用入门
Github简介及实用入门Github简介及实用入门
Github简介及实用入门Rongxing Liu
 
COSCUP 2015 開源之道-Git工作坊教學簡報
COSCUP 2015 開源之道-Git工作坊教學簡報COSCUP 2015 開源之道-Git工作坊教學簡報
COSCUP 2015 開源之道-Git工作坊教學簡報Bachue Zhou
 
Git & git flow
Git & git flowGit & git flow
Git & git flowAmo Wu
 
20170510 git 懶人包
20170510 git 懶人包20170510 git 懶人包
20170510 git 懶人包Chen-Ming Yang
 
Git introduction
Git introductionGit introduction
Git introductionmythnc
 
Git Essence Tutorial
Git Essence TutorialGit Essence Tutorial
Git Essence TutorialHo Kim
 
為自己學 Git
為自己學 Git為自己學 Git
為自己學 Git昀 李
 
Git & git hub v1.2
Git & git hub v1.2Git & git hub v1.2
Git & git hub v1.2Chris Chen
 
Git使用入门
Git使用入门Git使用入门
Git使用入门dpf2e
 
Git+使用教程
Git+使用教程Git+使用教程
Git+使用教程gemron
 
Git basis - usage
Git basis - usageGit basis - usage
Git basis - usageEason Cao
 
Yet another introduction to Git - from the bottom up
Yet another introduction to Git - from the bottom upYet another introduction to Git - from the bottom up
Yet another introduction to Git - from the bottom upWen-Tien Chang
 

Similar to Git教學 (20)

Git 入门实战
Git 入门实战Git 入门实战
Git 入门实战
 
Git 教學
Git 教學Git 教學
Git 教學
 
Learn git
Learn gitLearn git
Learn git
 
Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀
 
Git 超簡單學習懶人包(軟體程式版本控管系統)
Git 超簡單學習懶人包(軟體程式版本控管系統)Git 超簡單學習懶人包(軟體程式版本控管系統)
Git 超簡單學習懶人包(軟體程式版本控管系統)
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
Github简介及实用入门
Github简介及实用入门Github简介及实用入门
Github简介及实用入门
 
COSCUP 2015 開源之道-Git工作坊教學簡報
COSCUP 2015 開源之道-Git工作坊教學簡報COSCUP 2015 開源之道-Git工作坊教學簡報
COSCUP 2015 開源之道-Git工作坊教學簡報
 
Git & git flow
Git & git flowGit & git flow
Git & git flow
 
20170510 git 懶人包
20170510 git 懶人包20170510 git 懶人包
20170510 git 懶人包
 
Git introduction
Git introductionGit introduction
Git introduction
 
Git Essence Tutorial
Git Essence TutorialGit Essence Tutorial
Git Essence Tutorial
 
為自己學 Git
為自己學 Git為自己學 Git
為自己學 Git
 
Git & git hub v1.2
Git & git hub v1.2Git & git hub v1.2
Git & git hub v1.2
 
Git使用入门
Git使用入门Git使用入门
Git使用入门
 
Git+使用教程
Git+使用教程Git+使用教程
Git+使用教程
 
Git基础培训
Git基础培训Git基础培训
Git基础培训
 
Git basis - usage
Git basis - usageGit basis - usage
Git basis - usage
 
Yet another introduction to Git - from the bottom up
Yet another introduction to Git - from the bottom upYet another introduction to Git - from the bottom up
Yet another introduction to Git - from the bottom up
 
Git share
Git shareGit share
Git share
 

Git教學

  • 1. Git 簡易教學 姚芳德
  • 2. Host Rep Branch A Local Rep Local Rep Local Rep Branch A Branch A Branch A Branch A Branch B Branch B #2 Branch B Branch C Branch C Branch D Rep = Repository (知識庫)
  • 3. Branches are cheap and easy, so this is a good way to try something out。 -Linus Torvalds
  • 4. 本地端Git 流程 提交 加入檔案 加上註解 COMMIT 將CODE上傳至HOST Commit至 Master HOST審核 Master 更新
  • 5. Git 增加檔案 •git add . # 先將資料先暫存到預傳區 •git add filename • git add modify-file # 修改過的檔案, 也要 add. (不然 commit 要加上 -a 的參數) •git add -u # 只加修改過的檔案, 新增的檔案不加入. •git add -i # 進入互動模式 Git 提交檔案 •git commit •git commit -m 'commit message' •git commit -a -m 'commit -message' # 將所有修改過得檔案都 commit, 但是 新增的檔案 還是得要先 add. •git commit -a -v # -v 可以看到檔案哪些內容有被更改, -a 把所有修改的檔案都 commit
  • 6. Git 增加分支 •git branch # 列出目前有多少 branch •git branch new-branch # 產生新的 branch (名稱: new-branch), 若沒有特別指定, 會由目 前所在的 branch / master 直接複製一份. •git branch new-branch master # 由 master 產生新的 branch(new-branch) •git branch new-branch v1 # 由 tag(v1) 產生新的 branch(new- branch) •git branch -d new-branch # 刪除 new-branch •git branch -D new-branch # 強制刪除 new-branch •git checkout -b new-branch test # 產生新的 branch, 並同時切換過去 new-branch •# 與 remote repository 有關 •git branch -r # 列出所有 Repository branch •git branch -a # 列出所有 branch
  • 7. Git 切換分支 •git checkout branch-name # 切換到 branch-name •git checkout master # 切換到 master •git checkout -b new-branch master # 從 master 建立新的 new-branch, 並同時切換過去 new-branch •git checkout -b newbranch # 由現在的環境為基礎, 建立新的 branch •git checkout -b newbranch origin # 於 origin 的基礎, 建立新的 branch •git checkout filename # 還原檔案到 Repository 狀態 •git checkout HEAD . # 將所有檔案都 checkout 出來(最後一次 commit 的版本), 注意, 若有 修改的檔案都會被還原到上一版. (git checkout -f 亦可) •git checkout xxxx . # 將所有檔案都 checkout 出來(xxxx commit 的 版本, xxxx 是 commit 的編號前四碼), 注意, 若有修改的檔案都會被 還原到上一版. •git checkout -- * # 恢復到上一次 Commit 的狀態(* 改成檔名, 就可
  • 8. Git 合併分支 •git merge •git merge master •git merge new-branch
  • 9. Git 觀看差異 •git diff master # 與 Master 有哪些資料不同 •git diff --cached # 比較 staging area 跟本來的 Repository •git diff tag1 tag2 # tag1, 與 tag2 的 diff •git diff tag1:file1 tag2:file2 # tag1, 與 tag2 的 file1, file2 的 diff •git diff # 比較 目前位置 與 staging area •git diff --cached # 比較 staging area 與 Repository 差異 •git diff HEAD # 比較目前位置 與 Repository 差別 •git diff new-branch # 比較目前位置 與 branch(new-branch) 的 差別 •git diff --stat