講師: 王銘德
mingderwang@gmail.com
用 email 寄 tarballs, 或用patches. (兩年前, 我還看過)
濱野 純 維護 git source code.
一開始是 Linux kernel 版控在用.
五月, git 發明人 Linus Torvalds 到 Google 演講, 介紹什麼是 git
11 年後的今天...
(我們在這裡上 git 的課)
CVS (26 年前開始, 2008 穩定)
SVN (16年前開始, 2016 穩定)
bitkeeper, rcs -> cvs -> svn
2008 我們 KatDC 開始用 git
集中式
大部分的公司還在用
沒有什麼不好
team 在用, 我只好跟著用
絕對不要再用 tarballs 就好!!
分散式集中
大部分會比較小
分散, 造成比較可靠
自由度比較高
=> 比較 agile 一點
< 但我覺得這都還不是重點, agile 才是重點 >
SVN 沒有不好, git 也沒什麼了不起. 但我想分享的經驗是
git 比較不需要跟別人的 source code 等來等去...
< 以最常見的情況 hotfix 為例 >
< Git 的另一個好處是 "開 branches 不用錢" >
* local 你可以盡量開 branches
典型版空模式
local
local
local
local
remote
注意: 每個人會有一份 local copy
而且可能不樣的 branches
(按 往下按鍵)
$ git clone
$ git init
$ git branch -a
$ git add -A
$ git commit -m '說明...'
$ git checkout
$ git remote -v
$ git push origin <branch_name> --tag
$ git pull origin <branch_name> --tag
$ git tag
$ git log
$ git status
$ git diff
$ git merge --no-ff
$ git stash, git stash pop
// 從 remote 端 clone 一個 project 過來
$ cd /tmp
$ git clone https://github.com/nodeapps/helloworld.git
$ cd helloworld
$ git log
$ git tag
v0.2.2
$ git pull origin master
cd /tmp
mkdir myproject
cd myproject
git init
vi README.md
git add -A
git commit -m 'add README'
git tag v1.0
git status
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
$ git checkout -b develop
$ git checkout master
// 每次要 commit 程式前, 先把所有更新 add 進來 tracking
$ git status
$ git add -A
// 每個 branch 上的圓球就是一個 commit
$ git status
$ git log
$ git commit -m '一行說明'
$ git log
// 每個 branch 都能 commit
// 盡量只在 features, hotfix
branches 上改 code.
// checkout 用來跳 local branch 的
$ git checkout -b new_feature develop
$ git checkout -b release-1.2
$ git branch -a
$ git checkout master
$ git checkout <tag_name>
// 注意: checkout tag_name 是臨時 branch name (例如 19b1a5b)
feature-1 feature 2
$ cd /tmp/myfirstVertx
$ git remote -v
origin ssh://git@git.nkg-cloud.com:10022/mingderwang/myfirstVertx.git (fetch)
origin ssh://git@git.nkg-cloud.com:10022/mingderwang/myfirstVertx.git (push)
$ git remote add private git@redmine.log4analytics.com:/opt/git/myfirstVertx.git
$ git push private master --tag
$ git remote -v
origin ssh://git@git.nkg-cloud.com:10022/mingderwang/myfirstVertx.git (fetch)
origin ssh://git@git.nkg-cloud.com:10022/mingderwang/myfirstVertx.git (push)
private git@redmine.log4analytics.com:/opt/git/myfirstVertx.git (fetch)
private git@redmine.log4analytics.com:/opt/git/myfirstVertx.git (push)
// 將 local 某個 branch 跟 remote 某個 branch 同步
$ git pull origin master
$ git push origin master
$ git checkout develop // 跳到 develop branch
$ git pull origin develop
$ git push origin develop
$ git checkout master
$ git pull origin master
// git pull = git fetch + git merge
$ git tag
$ git checkout <tag_id>
$ git checkout master
$ git tag v2.0
$ git tag
$ git push origin master --tag
$ git log
// 看當時狀態
$ git diff
$ git diff 1586e1f3b28374c599ce6555d01d1a0f7e96b643
$ git checkout develop
$ git merge --no-ff myfeature
$ git branch -d myfeature
$ git push origin develop
// 改到一半的 code
// 突然需要 hotfix 怎麼辦
$ git stash
// 暫存改到一半的 code
// 先做其他事
// 等做完事後,
$ git stash pop
// 回到原來狀態
+ 不斷得練習
(請按 右鍵)
<<<<<<< HEAD
- "5140:5140/udp"
expose:
- "5140/udp"
=======
- "5011:5011"
- "5140:5140/udp"
- "5013:5013"
expose:
- "5011"
- "5140/udp"
- "5013"
>>>>>>> 1f3b6a13b19d5723589d5ba47676194fda7b8fca
挑你要的部分, 其他行刪掉
整塊不要, 刪掉
(只能綠或紅,二選一)
刪掉