SlideShare uma empresa Scribd logo
1 de 54
Git
Outline
❖ What’s Git?
❖ Why Git?
❖ Basic Operation
➢ Setup
➢ Status Transformation
➢ GitLab & Cooperation
❖ Branch
❖ Branch Management
2
What’s Git?
Distributed Version Control
「教授今天給了回家作業,題目放在講桌,下課離開前記得拿
回家寫,下次上課一起交到講桌」
3
What’s Git?
Distributed Version Control
「下課離開前記得拿回家寫」
4
❏ 大家題目都一樣
❏ 這作業離開學校一樣能寫
❏ 互不受干擾
❏ 可協作
Why Git?
Local Branching and Merging
5
Why Git?
Small and Fast
6
Why Git?
Staging Area
7
Why Git?
Distributed & GitLab
8
Basic Operation
❖ Setup
❖ Status Transformation
❖ GitLab & Cooperation
9
Setup Git Download
設定識別資料
檢視所有Config設定
檢視/修改 Config的某個參數
$ git config --global user.name “aaabbb”
$ git config --global user.email aaabbb@gmail.com
$ git config --list
$ git config user.name # 檢視
$ git config user.name “xxxxx” # 修改
10
Git Initial
在現有無版控的專案
$ cd <專案的資料夾路徑>
$ git init
$ git status #可以先看個檔案狀態
$ git add .
$ git status #add後也可以看個檔案狀態
$ git commit -m “intitial commit”
在要clone下來的某個路徑
#下載一整個remote專案包括所有歷史紀錄
$ git clone <Repository Directory>
11
Status Transformation
工作目錄底下的檔案可以分作兩種:被追蹤 & 尚被追蹤
只有被追蹤的檔案能
作版本控管
12
Status Transformation
已修改 已暫存 已提交 已上傳
工作目錄 暫存目錄 git目錄 GitLab
add commit
clone/fetch
push
checkout
Local
13
14
Status Transformation - Track Files
檢視當前git所管理的資料狀態
$ git status
新增要追蹤的檔案
$ git add index.html 一次把目錄下的所有檔案加入:
$ git add .
15
Status Transformation - Modify Tracked Files
已修改 已暫存
工作目錄 暫存目錄
add
modify
修改一個先前已經追蹤過的檔案
修改一個先前已經追蹤過的檔案
$ git status
$ git add index.html
$ git status
16
Status Transformation -Ignored Files
忽略不想追蹤的檔案
git add . 不會加進來
git status 不會去檢查
{path}/.gitignore
17
Status Transformation - Commit Files
提交站存區裡的內容到git資料庫
$ git commit -m “commit message”
#或是
$ git commit
跳過提交暫存區的動作 直接commit
$ git commit -a -m “commit message”
已修改 已暫存 已提交
工作目錄 暫存目錄 git目錄
git commit -m
git commit -a -m
18
GitLab & Cooperation - SSH Key
Generate SSH Key & Add it to GitLab:
https://gitlab.com/help/ssh/README
19
GitLab & Cooperation - Add Remote Repository
新增remote repository URL
# git remote add <name> <url>
$ git remote add origin https://gitlab.softbi.com/OCB_WMS/OCB_WMS_AP.git
$ git remote add origin ssh://git@gitlab.softbi.com:3078/OCB_WMS/OCB_WMS_AP.git
檢視remote git 清單
$ git remote -v
http(s): 可讀寫,方便,較慢
ssh: 適合讀寫,一定是加密,較快
git: 唯讀
20
GitLab & Cooperation - Push & Pull
push to remote
# 將master branch 上傳到remote origin倉庫
$ git push origin master
# 上傳到remote origin倉庫並且追蹤該branch
$ git push -u origin master
pull from remote
# 將remote的master branch
$ git pull origin master
其他pull方式
# 避免無謂的merge可下
$ git pull --rebase origin master
# 先將remote所有branch/tag拉下來,再作rebase
$ git fetch
$ git rebase origin/master 21
Branch - Commit Log
22
Branch - Commit Log
23
Branch - Create Branch
新增branch
$ git branch testing
HEAD所指的地方就是目前commit
預設branch為master
新增一個branch -> testing
24
Branch - Checkout Branch
切換branch
$ git checkout testing
接下來commit會發
生什麼事呢?
25
Branch - Commit in another Branch
26
Branch - Branch Split
$ git checkout master
$ git commit -a -m “modify something”
27
Branch - Merge
$ git checkout -b iss53
$ git commit -a -m “modify something”
28
今天有個issue53要修正
Branch - Merge
$ git checkout master
$ git checkout -b hotfix
$ git commit -a -m “fixed the bug”
29
發現有個bug要緊急修正
$ git checkout master
$ git merge hotfix
30
$ git branch -d hotfix
$ git checkout iss53
$ git commit -a -m “modify something”
31
$ git checkout master
$ git merge iss53
$ git branch -d iss53
32
Branch - Conflict
在不同的branch上,修改了同一個檔案的同一部分,merge時就會衝突而無法順
利地合併
$ git merge iss53
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.
33
Branch - Conflict Recovery
<<<<<<< HEAD
<div id="footer">contact : email.support@github.com</div>
=======
<div id="footer">
please contact us at support@github.com
</div>
>>>>>>> iss53
<div id="footer">
please contact us at support@github.com
</div>
手動決定要保留的部分
34
Branch - Conflict Recovery
# 確認檔案狀態
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: index.html
# 確認解決衝突後就可以commit出去
# 直接下git commit即可,git會自動加Merge branch ‘iss53’ into master的message
$ git commit
35
Branch - Conflict Recovery
發生confict 時的處理步驟:
1. 抉擇conflict files要留下哪個branch內容(或是兩邊都有一些code要保留)
2. 使用git add 將處理好的檔案加入stage
3. 反覆步驟 1~2 直到所有 confict 處理完畢
4. git commit 提交合併訊息
36
Branch - Stash
37
$ git status
$ git stash
$ git stash list
$ git stash pop
$ git stash pop stash@{n}
Branch - Rebase
38
$ git checkout master
$ git merge experiment
Branch - Rebase
39
$ git checkout experiment
$ git rebase master
$ git checkout master
$ git merge experiment
Branch - Reset
$ git reset HEAD^
$ git reset HEAD <file>
$ git reset HEAD~3
$ git reset <commit>
40
Branch - Revert
41
# 還原某一個commit的變更內容,並且commit
$ git revert <commit>
42
Working
Directory
Staging
Area
Local
Repository
Remote/Origin
Repository
Remote
Repository
Local Remote
git add git commit git push
git pull
git merge git fetch
git fetchgit rebase
git pull --rebase
Branch Management
Git/Github Flow
GUI Tool - SourceTree
43
Branch Management
44
Git Flow - Master & Develop branch
45https://github.com/nvie/gitflow/wiki/Installation
Git Flow - Develop & Feature branch
$ git flow feature start myfeature
# 等於以下的事情
$ git checkout -b feature/myfeature develop
$ git flow feature finish myfeature
# 等於以下的事情
$ git checkout develop
$ git merge --no-ff myfeature
$ git branch -d feature/myfeature
46
Git Flow - Release & Hotfix branch
47
48
Github Flow
49
SourceTree
50
教學
SVN to Git
# git svn clone <svn repository> --stdlayout
$ git svn clone
svn://bisvn.softbi.com:80/taiwan/OCB/WMS/SRC/AP --stdlayout
$ git svn clone <svn repository> --trunk=<主幹路徑> --
branches=<分支路徑> --tags=<標籤路徑>
$ git svn show-ignore >> .gitignore
$ git add .gitignore
$ git commit -m “convert svn:ignore properties to .gitignore”
51
Practice : 連結
52
53
博客來
Q&A
54

Mais conteúdo relacionado

Mais procurados

15分でわかるGit入門
15分でわかるGit入門15分でわかるGit入門
15分でわかるGit入門to_ueda
 
Gitはじめの一歩
Gitはじめの一歩Gitはじめの一歩
Gitはじめの一歩Ayana Yokota
 
はじめてのGit forデザイナー&コーダー
はじめてのGit forデザイナー&コーダーはじめてのGit forデザイナー&コーダー
はじめてのGit forデザイナー&コーダーSaeko Yamamoto
 
一人でもはじめるGitでバージョン管理
一人でもはじめるGitでバージョン管理一人でもはじめるGitでバージョン管理
一人でもはじめるGitでバージョン管理Takafumi Yoshida
 
バージョン管理のワークフロー
バージョン管理のワークフローバージョン管理のワークフロー
バージョン管理のワークフローadd20
 
初心者 Git 上手攻略
初心者 Git 上手攻略初心者 Git 上手攻略
初心者 Git 上手攻略Lucien Lee
 
やりなおせる Git 入門
やりなおせる Git 入門やりなおせる Git 入門
やりなおせる Git 入門Tomohiko Himura
 
Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀Wen-Tien Chang
 
Gitのよく使うコマンド
Gitのよく使うコマンドGitのよく使うコマンド
Gitのよく使うコマンドYUKI Kaoru
 
社内Git勉強会向け資料
社内Git勉強会向け資料社内Git勉強会向け資料
社内Git勉強会向け資料Hiroki Saiki
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHubJames Gray
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notesglen_a_smith
 
はじめようGit
はじめようGitはじめようGit
はじめようGittechscore
 
Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash CourseNilay Binjola
 
Learning Git and GitHub - BIT GDSC.pdf
Learning Git and GitHub - BIT GDSC.pdfLearning Git and GitHub - BIT GDSC.pdf
Learning Git and GitHub - BIT GDSC.pdfJayprakash677449
 

Mais procurados (20)

15分でわかるGit入門
15分でわかるGit入門15分でわかるGit入門
15分でわかるGit入門
 
Gitはじめの一歩
Gitはじめの一歩Gitはじめの一歩
Gitはじめの一歩
 
はじめてのGit forデザイナー&コーダー
はじめてのGit forデザイナー&コーダーはじめてのGit forデザイナー&コーダー
はじめてのGit forデザイナー&コーダー
 
一人でもはじめるGitでバージョン管理
一人でもはじめるGitでバージョン管理一人でもはじめるGitでバージョン管理
一人でもはじめるGitでバージョン管理
 
バージョン管理のワークフロー
バージョン管理のワークフローバージョン管理のワークフロー
バージョン管理のワークフロー
 
初心者 Git 上手攻略
初心者 Git 上手攻略初心者 Git 上手攻略
初心者 Git 上手攻略
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
いつやるの?Git入門
いつやるの?Git入門いつやるの?Git入門
いつやるの?Git入門
 
やりなおせる Git 入門
やりなおせる Git 入門やりなおせる Git 入門
やりなおせる Git 入門
 
Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀
 
Gitのよく使うコマンド
Gitのよく使うコマンドGitのよく使うコマンド
Gitのよく使うコマンド
 
社内Git勉強会向け資料
社内Git勉強会向け資料社内Git勉強会向け資料
社内Git勉強会向け資料
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
 
はじめようGit
はじめようGitはじめようGit
はじめようGit
 
Advanced Git
Advanced GitAdvanced Git
Advanced Git
 
Git workflows
Git workflowsGit workflows
Git workflows
 
Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash Course
 
Git vs svn
Git vs svnGit vs svn
Git vs svn
 
Learning Git and GitHub - BIT GDSC.pdf
Learning Git and GitHub - BIT GDSC.pdfLearning Git and GitHub - BIT GDSC.pdf
Learning Git and GitHub - BIT GDSC.pdf
 

Destaque

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
 
InterConnect2016_4932
InterConnect2016_4932InterConnect2016_4932
InterConnect2016_4932Clare Carty
 
New Continuous Release and Deployment Capabilities for CICS Customers v4
New Continuous Release and Deployment Capabilities for CICS Customers v4New Continuous Release and Deployment Capabilities for CICS Customers v4
New Continuous Release and Deployment Capabilities for CICS Customers v4Susan Yoskin
 
Basic principles of Git
Basic principles of GitBasic principles of Git
Basic principles of Gitphuongvohuy
 
Integrations, UI Enhancements and Cloud – See What’s New with IBM UrbanCode D...
Integrations, UI Enhancements and Cloud – See What’s New with IBM UrbanCode D...Integrations, UI Enhancements and Cloud – See What’s New with IBM UrbanCode D...
Integrations, UI Enhancements and Cloud – See What’s New with IBM UrbanCode D...IBM UrbanCode Products
 
Git-ing out of your git messes
Git-ing out of  your git messesGit-ing out of  your git messes
Git-ing out of your git messesKatie Sylor-Miller
 
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
 
Linux Day 2015 Genova
Linux Day 2015 GenovaLinux Day 2015 Genova
Linux Day 2015 Genovamperrando
 
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
 

Destaque (20)

Getting Git Right
Getting Git RightGetting Git Right
Getting Git Right
 
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 101 Presentation
Git 101 PresentationGit 101 Presentation
Git 101 Presentation
 
InterConnect2016_4932
InterConnect2016_4932InterConnect2016_4932
InterConnect2016_4932
 
New Continuous Release and Deployment Capabilities for CICS Customers v4
New Continuous Release and Deployment Capabilities for CICS Customers v4New Continuous Release and Deployment Capabilities for CICS Customers v4
New Continuous Release and Deployment Capabilities for CICS Customers v4
 
Basic principles of Git
Basic principles of GitBasic principles of Git
Basic principles of Git
 
Integrations, UI Enhancements and Cloud – See What’s New with IBM UrbanCode D...
Integrations, UI Enhancements and Cloud – See What’s New with IBM UrbanCode D...Integrations, UI Enhancements and Cloud – See What’s New with IBM UrbanCode D...
Integrations, UI Enhancements and Cloud – See What’s New with IBM UrbanCode D...
 
Git-ing out of your git messes
Git-ing out of  your git messesGit-ing out of  your git messes
Git-ing out of your git messes
 
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
 
GITT (part 1 of 2)
GITT (part 1 of 2)GITT (part 1 of 2)
GITT (part 1 of 2)
 
Linux Day 2015 Genova
Linux Day 2015 GenovaLinux Day 2015 Genova
Linux Day 2015 Genova
 
Perchè Git?
Perchè Git?Perchè Git?
Perchè Git?
 
Git–SVN
Git–SVNGit–SVN
Git–SVN
 
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
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Introduzione a git
Introduzione a gitIntroduzione a git
Introduzione a git
 
Introduzione a Git
Introduzione a GitIntroduzione a Git
Introduzione a Git
 
Git best practices
Git best practicesGit best practices
Git best practices
 
Mini git tutorial
Mini git tutorialMini git tutorial
Mini git tutorial
 

Semelhante a Git基礎介紹

Introduction to git
Introduction to gitIntroduction to git
Introduction to gitBo-Yi Wu
 
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 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹PingLun Liao
 
Git in a nutshell
Git in a nutshellGit in a nutshell
Git in a nutshellNelson Tai
 
Git 入门实战
Git 入门实战Git 入门实战
Git 入门实战icy leaf
 
20170510 git 懶人包
20170510 git 懶人包20170510 git 懶人包
20170510 git 懶人包Chen-Ming Yang
 
Git 超簡單學習懶人包(軟體程式版本控管系統)
Git 超簡單學習懶人包(軟體程式版本控管系統)Git 超簡單學習懶人包(軟體程式版本控管系統)
Git 超簡單學習懶人包(軟體程式版本控管系統)flylon
 
Git Essence Tutorial
Git Essence TutorialGit Essence Tutorial
Git Essence TutorialHo Kim
 
Git使用入门
Git使用入门Git使用入门
Git使用入门dpf2e
 
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
 
Git原理与实战 201607
Git原理与实战 201607Git原理与实战 201607
Git原理与实战 201607Charles Tang
 
Git introduction
Git introductionGit introduction
Git introductionmythnc
 
Git内部培训文档
Git内部培训文档Git内部培训文档
Git内部培训文档superwen
 
Git and git hub
Git and git hubGit and git hub
Git and git hub唯 李
 
Git 使用介绍
Git 使用介绍Git 使用介绍
Git 使用介绍medcl
 
First meetingwithgit
First meetingwithgitFirst meetingwithgit
First meetingwithgitRhythm Sun
 

Semelhante a Git基礎介紹 (20)

Introduction to git
Introduction to gitIntroduction to git
Introduction to 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 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹
 
Git in a nutshell
Git in a nutshellGit in a nutshell
Git in a nutshell
 
Git 入门实战
Git 入门实战Git 入门实战
Git 入门实战
 
20170510 git 懶人包
20170510 git 懶人包20170510 git 懶人包
20170510 git 懶人包
 
Git 超簡單學習懶人包(軟體程式版本控管系統)
Git 超簡單學習懶人包(軟體程式版本控管系統)Git 超簡單學習懶人包(軟體程式版本控管系統)
Git 超簡單學習懶人包(軟體程式版本控管系統)
 
Git教學
Git教學Git教學
Git教學
 
Git Tutorial
Git TutorialGit Tutorial
Git Tutorial
 
Git Essence Tutorial
Git Essence TutorialGit Essence Tutorial
Git Essence Tutorial
 
Git使用入门
Git使用入门Git使用入门
Git使用入门
 
Git share
Git shareGit share
Git share
 
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原理与实战 201607
Git原理与实战 201607Git原理与实战 201607
Git原理与实战 201607
 
Git introduction
Git introductionGit introduction
Git introduction
 
Git内部培训文档
Git内部培训文档Git内部培训文档
Git内部培训文档
 
Git and git hub
Git and git hubGit and git hub
Git and git hub
 
Git 使用介绍
Git 使用介绍Git 使用介绍
Git 使用介绍
 
First meetingwithgit
First meetingwithgitFirst meetingwithgit
First meetingwithgit
 

Git基礎介紹

  • 1. Git
  • 2. Outline ❖ What’s Git? ❖ Why Git? ❖ Basic Operation ➢ Setup ➢ Status Transformation ➢ GitLab & Cooperation ❖ Branch ❖ Branch Management 2
  • 3. What’s Git? Distributed Version Control 「教授今天給了回家作業,題目放在講桌,下課離開前記得拿 回家寫,下次上課一起交到講桌」 3
  • 4. What’s Git? Distributed Version Control 「下課離開前記得拿回家寫」 4 ❏ 大家題目都一樣 ❏ 這作業離開學校一樣能寫 ❏ 互不受干擾 ❏ 可協作
  • 5. Why Git? Local Branching and Merging 5
  • 9. Basic Operation ❖ Setup ❖ Status Transformation ❖ GitLab & Cooperation 9
  • 10. Setup Git Download 設定識別資料 檢視所有Config設定 檢視/修改 Config的某個參數 $ git config --global user.name “aaabbb” $ git config --global user.email aaabbb@gmail.com $ git config --list $ git config user.name # 檢視 $ git config user.name “xxxxx” # 修改 10
  • 11. Git Initial 在現有無版控的專案 $ cd <專案的資料夾路徑> $ git init $ git status #可以先看個檔案狀態 $ git add . $ git status #add後也可以看個檔案狀態 $ git commit -m “intitial commit” 在要clone下來的某個路徑 #下載一整個remote專案包括所有歷史紀錄 $ git clone <Repository Directory> 11
  • 12. Status Transformation 工作目錄底下的檔案可以分作兩種:被追蹤 & 尚被追蹤 只有被追蹤的檔案能 作版本控管 12
  • 13. Status Transformation 已修改 已暫存 已提交 已上傳 工作目錄 暫存目錄 git目錄 GitLab add commit clone/fetch push checkout Local 13
  • 14. 14
  • 15. Status Transformation - Track Files 檢視當前git所管理的資料狀態 $ git status 新增要追蹤的檔案 $ git add index.html 一次把目錄下的所有檔案加入: $ git add . 15
  • 16. Status Transformation - Modify Tracked Files 已修改 已暫存 工作目錄 暫存目錄 add modify 修改一個先前已經追蹤過的檔案 修改一個先前已經追蹤過的檔案 $ git status $ git add index.html $ git status 16
  • 17. Status Transformation -Ignored Files 忽略不想追蹤的檔案 git add . 不會加進來 git status 不會去檢查 {path}/.gitignore 17
  • 18. Status Transformation - Commit Files 提交站存區裡的內容到git資料庫 $ git commit -m “commit message” #或是 $ git commit 跳過提交暫存區的動作 直接commit $ git commit -a -m “commit message” 已修改 已暫存 已提交 工作目錄 暫存目錄 git目錄 git commit -m git commit -a -m 18
  • 19. GitLab & Cooperation - SSH Key Generate SSH Key & Add it to GitLab: https://gitlab.com/help/ssh/README 19
  • 20. GitLab & Cooperation - Add Remote Repository 新增remote repository URL # git remote add <name> <url> $ git remote add origin https://gitlab.softbi.com/OCB_WMS/OCB_WMS_AP.git $ git remote add origin ssh://git@gitlab.softbi.com:3078/OCB_WMS/OCB_WMS_AP.git 檢視remote git 清單 $ git remote -v http(s): 可讀寫,方便,較慢 ssh: 適合讀寫,一定是加密,較快 git: 唯讀 20
  • 21. GitLab & Cooperation - Push & Pull push to remote # 將master branch 上傳到remote origin倉庫 $ git push origin master # 上傳到remote origin倉庫並且追蹤該branch $ git push -u origin master pull from remote # 將remote的master branch $ git pull origin master 其他pull方式 # 避免無謂的merge可下 $ git pull --rebase origin master # 先將remote所有branch/tag拉下來,再作rebase $ git fetch $ git rebase origin/master 21
  • 22. Branch - Commit Log 22
  • 23. Branch - Commit Log 23
  • 24. Branch - Create Branch 新增branch $ git branch testing HEAD所指的地方就是目前commit 預設branch為master 新增一個branch -> testing 24
  • 25. Branch - Checkout Branch 切換branch $ git checkout testing 接下來commit會發 生什麼事呢? 25
  • 26. Branch - Commit in another Branch 26
  • 27. Branch - Branch Split $ git checkout master $ git commit -a -m “modify something” 27
  • 28. Branch - Merge $ git checkout -b iss53 $ git commit -a -m “modify something” 28 今天有個issue53要修正
  • 29. Branch - Merge $ git checkout master $ git checkout -b hotfix $ git commit -a -m “fixed the bug” 29 發現有個bug要緊急修正
  • 30. $ git checkout master $ git merge hotfix 30
  • 31. $ git branch -d hotfix $ git checkout iss53 $ git commit -a -m “modify something” 31
  • 32. $ git checkout master $ git merge iss53 $ git branch -d iss53 32
  • 33. Branch - Conflict 在不同的branch上,修改了同一個檔案的同一部分,merge時就會衝突而無法順 利地合併 $ git merge iss53 Auto-merging index.html CONFLICT (content): Merge conflict in index.html Automatic merge failed; fix conflicts and then commit the result. 33
  • 34. Branch - Conflict Recovery <<<<<<< HEAD <div id="footer">contact : email.support@github.com</div> ======= <div id="footer"> please contact us at support@github.com </div> >>>>>>> iss53 <div id="footer"> please contact us at support@github.com </div> 手動決定要保留的部分 34
  • 35. Branch - Conflict Recovery # 確認檔案狀態 $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: index.html # 確認解決衝突後就可以commit出去 # 直接下git commit即可,git會自動加Merge branch ‘iss53’ into master的message $ git commit 35
  • 36. Branch - Conflict Recovery 發生confict 時的處理步驟: 1. 抉擇conflict files要留下哪個branch內容(或是兩邊都有一些code要保留) 2. 使用git add 將處理好的檔案加入stage 3. 反覆步驟 1~2 直到所有 confict 處理完畢 4. git commit 提交合併訊息 36
  • 37. Branch - Stash 37 $ git status $ git stash $ git stash list $ git stash pop $ git stash pop stash@{n}
  • 38. Branch - Rebase 38 $ git checkout master $ git merge experiment
  • 39. Branch - Rebase 39 $ git checkout experiment $ git rebase master $ git checkout master $ git merge experiment
  • 40. Branch - Reset $ git reset HEAD^ $ git reset HEAD <file> $ git reset HEAD~3 $ git reset <commit> 40
  • 41. Branch - Revert 41 # 還原某一個commit的變更內容,並且commit $ git revert <commit>
  • 42. 42 Working Directory Staging Area Local Repository Remote/Origin Repository Remote Repository Local Remote git add git commit git push git pull git merge git fetch git fetchgit rebase git pull --rebase
  • 45. Git Flow - Master & Develop branch 45https://github.com/nvie/gitflow/wiki/Installation
  • 46. Git Flow - Develop & Feature branch $ git flow feature start myfeature # 等於以下的事情 $ git checkout -b feature/myfeature develop $ git flow feature finish myfeature # 等於以下的事情 $ git checkout develop $ git merge --no-ff myfeature $ git branch -d feature/myfeature 46
  • 47. Git Flow - Release & Hotfix branch 47
  • 48. 48
  • 51. SVN to Git # git svn clone <svn repository> --stdlayout $ git svn clone svn://bisvn.softbi.com:80/taiwan/OCB/WMS/SRC/AP --stdlayout $ git svn clone <svn repository> --trunk=<主幹路徑> -- branches=<分支路徑> --tags=<標籤路徑> $ git svn show-ignore >> .gitignore $ git add .gitignore $ git commit -m “convert svn:ignore properties to .gitignore” 51

Notas do Editor

  1. 資料來源 https://git-scm.com/book/zh-tw/v1 http://zoomq.qiniudn.com/ZQScrapBook/ZqFLOSS/data/20081210180347/