2009年4月12日 星期日

How To Help FormosaBBS (二)

因為文章落落長,所以切成兩部份。
延續前一篇:How To Help FormosaBBS (一)


10. 其他 git 使用說明。(詳細請參考:Getting Git)
=== 以下取自於 pigfoot 文章 ===
###
### 新功能我習慣開一個 (local) branch, 也可以用 git stash 代替
### 事實上 git stash 就是簡化版的 branch+checkout
### 所以我這邊是自己手動作 branch+checkout
###
### 第一先看一下現在的 branch, 應該 local 應該只有 master
### 我習慣 master 會和 remote 的 source 同步 (就是 origin/master)
### 那 origin/* 裡的是 remote branch, 是大家共享的 branch,
### 預設就是 origin/master 把 source fetch 回來到 local 的 master
###
sojia [/tmp/formosa] -pigfoot- [W1] git branch -a
* master
origin/HEAD
origin/master
origin/pmore

###
### 開一個 local branch 叫 remove_poll, 然後到那個 branch 裡
### 其實 branch 我就是當成一個 feature
### git checkout -b remove_poll 等效於:
### git branch remove_poll ; git checkout remove_poll
###
sojia [/tmp/formosa] -pigfoot- [W1] git checkout -b remove_poll
Switched to a new branch "remove_poll"

###
### Double confirm 一下
### 綠色是 local branch, 紅色是 remote branch
###
sojia [/tmp/formosa] -pigfoot- [W1] git branch -a
master
* remove_poll
origin/HEAD
origin/master
origin/pmore

###
### 然後進行開發和測試的 loop
###
(hack, hack, hack)

###
### 開發完了, check 一下 status
### 綠色的就是有 git add 過的, 紅色的就是沒有 git add 過的
###
sojia [/tmp/formosa] -pigfoot- [W1] git status
# On branch remove_poll
# Changes to be committed:
# (use "git reset HEAD ..." to unstage)
#
# renamed: include/config.h -> include/bbsconfig.h
#
# Changed but not updated:
# (use "git add ..." to update what will be committed)
#
# modified: bbsweb/Makefile.in
# modified: configure.ac
# modified: csbbs/Makefile.in
# modified: include/bbs.h
# modified: lib/Makefile.in
# modified: lib/bbslib.c
# modified: lib/conf.c
# modified: lib/mod_shm.c
# modified: lib/modetype.c
# modified: src/Makefile.in
# modified: src/bbschatd.c
# modified: src/io.c
# modified: src/main.c
# modified: util/Makefile.in

###
### 所以 git add, 記錄哪些檔案有變動過
###
sojia [/tmp/formosa] -pigfoot- [W1] git add configure.ac

###
### 省略, 再打 git status 應該就都會是綠色的了
### 接著就是 commit 了
###
sojia [/tmp/formosa] -pigfoot- [W1] git commit

###
### 確定一下還在 remove_poll 這個 branch 裡
###
sojia [/tmp/formosa] -pigfoot- [W1] git branch
master
* remove_poll

###
### 跳回去 master, 準備 push 到 remote (這裡是指 github 的 origin/master)
###
sojia [/tmp/formosa] -pigfoot- [W1] git checkout master
Switched to branch "master"

###
### 確定一下是不是跳回去 master 裡了
###
sojia [/tmp/formosa] -pigfoot- [W1] git branch
* master
remove_poll

###
### 再 sync 一下 source. 沒有東西就是代表沒有新的 commit 被人 push 到 remote
###
sojia [/tmp/formosa] -pigfoot- [W1] git fetch
Enter passphrase for key '/home/pigfoot/.ssh/id_dsa':

###
### 舉一個在我們開發的時候, 別人剛好有 push 他們的 commit 的例子
###
sojia [/tmp/formosa] -pigfoot- [W1] git fetch
Enter passphrase for key '/home/pigfoot/.ssh/id_dsa':
remote: Counting objects: 110, done.
remote: Compressing objects: 100% (64/64), done.
remote: Total 64 (delta 52), reused 0 (delta 0)
Unpacking objects: 100% (64/64), done.
From git@github.com:pigfoot/formosa
4fff3c6..01f688e master -> origin/master

###
### 看一下狀況. 下面的是指我們的 master(local), 比 remote 的 master(origin)
### 還落後 8 個 commits (就是有 8 個 commits 是新的意思)
### 但是這是可以作 fast-forwarded, 意思是 git 可以快速的把我們 master tree,
### 和 remote 的 master tree 作自動 merge.
###
sojia [/tmp/formosa] -pigfoot- [W1] git status
# On branch master# Your branch is behind 'origin/master' by 8 commits, and can be
# fast-forwarded.
# nothing to commit (working directory clean)

###
### 沒啥問題我就會作 rebase. 因為我們 的 master(local),
### 有在 follow remote master(origin), 所以沒啥問題
###
sojia [/tmp/formosa] -pigfoot- [W1] git rebase -v origin
Changes from 44711bd6ae5a204f2d to 4fff3c650b4ae56c53cc1820e847b1971757f:
.gitignore 1 -
Makefile.in 2 -
lib/Makefile.in 9 +-
lib/ap_board.c 11 ++-
lib/libproto.h 279 +++++++++++++++++++------------------
lib/misc.c 2 +-
lib/mod_record.c 3 +-
lib/mod_sem.c 1 +
lib/mod_shm.c 1 -
lib/mod_zap.c 1 +
lib/modetype.c 2 +-
lib/strlcat.c 1 +
lib/strlcpy.c 1 +
src/board.c 3 -
src/tsbbs.h 248 +++++++++++++++++++++++++++++--------
15 files changed, 366 insertions(+), 199 deletions(-)
First, rewinding head to replay your work on top of it...
Fast-forwarded master to origin.

###
### Ok, 現在就是和 remote master(origin) 同步了,
### 也和 git fetch 沒有結果是一樣的狀況了.
###
sojia [/tmp/formosa] -pigfoot- [W1] git status
# On branch masternothing to commit (working directory clean)

###
### 確定和 remote master(origin) 是一樣的之後,
### 接著把 remove_poll 這個 branch 的所有 commit merge 回 master(local).
### 這裡是用 git merge remove_poll, 但是請用 git rebase -v remove_poll
### 不然可能多一個 commit for merge info:
### "merged branch 'master' of git@github.com:pigfoot/formosa"
###
sojia [/tmp/formosa] -pigfoot- [W1] git merge remove_poll
Updating 8247c97..0719de4
Fast forward
bbsweb/Makefile.in 2 +-
configure.ac 6 ++++-
csbbs/Makefile.in 2 +-
include/bbs.h 9 +------
include/{config.h => bbsconfig.h} 0
lib/Makefile.in 2 +-
lib/bbslib.c 2 +-
lib/conf.c 2 +-
lib/mod_shm.c 2 +-
lib/modetype.c 2 +-
src/Makefile.in 2 +-
src/bbschatd.c 10 +-------
src/io.c 14 +++++------
src/main.c 44 ++++++++--------------------------
util/Makefile.in 2 +-
15 files changed, 33 insertions(+), 68 deletions(-)
rename include/{config.h => bbsconfig.h} (100%)

###
### Merge 完沒有問題, 就可以 push 回 remote (就是 github 的 origin/master)
### 預設的狀況下, git push 是 git push origin master 的縮寫
### 很明顯的就是把 local 的 master, push 回 remote 的 origin(/master)
###
sojia [/tmp/formosa] -pigfoot- [W1] git push
Enter passphrase for key '/home/pigfoot/.ssh/id_dsa':
Counting objects: 43, done.
Compressing objects: 100% (22/22), done.
Writing objects: 100% (22/22), 2.06 KiB, done.
Total 22 (delta 21), reused 0 (delta 0)
To git@github.com:pigfoot/formosa.git
8247c97..0719de4 master -> master

###
### 事情做完, 在認真工作之前, 我會把剛剛開的 local branch 刪除, 反正用不到
### 不過不刪也沒關係, 因為這也是 local 這裡才有記錄
### 別人或是自己再重新 clone 是不會有這個 branch 的
###
sojia [/tmp/formosa] -pigfoot- [W1] git branch -d remove_poll
Deleted branch remove_poll.

###
### Double confirm 一下是不是不見了
###
sojia [/tmp/formosa] -pigfoot- [W1] git branch -a
* master
origin/HEAD
origin/master
origin/pmore
=== 以上是引用分隔線 ===

希望對各位有幫助 ^_^

How To Help FormosaBBS (一)

Formosa BBS Community Edition (以下簡稱為,FBCE) 是由一群佛心來著人士所維護之 BBS 開放原碼,如果您也願意來協助 FBCE 開發,在此提供以下方法:(感謝 coodavid, kmwang, pigfoot, zmx 幫忙補齊)


1. FBCE 目前開放原碼 hosting 於 GitHub, 在此建議您也申請一個 github account 方便 code merge.
GitHub -> Sign up now!

2. 產生 ssh key pair, 此用於 code 傳送。(詳細可參考:Providing your SSH Key)
$ ssh-keygen -b 4096 -t rsa -f ~/.ssh/github.id_rsa
Generating public/private rsa key pair.
Created directory '/home/account/.ssh'.
Enter passphrase (empty for no passphrase): (存取此 key 的密碼)
Enter same passphrase again:
Your identification has been saved in /home/account/.ssh/github.id_rsa.
Your public key has been saved in /home/account/.ssh/github.id_rsa.pub.
The key fingerprint is:aa:bb:cc:dd:ee:ff:1a:1b:1c:1d:1e:1f:2a:2b:2c:2d account@host
The key's randomart image is:
+--[ RSA 4096]----+
Orz...
>_<...
O_o...
. . E...
+------------------+

3. 上傳您所產生出來的 public key 至 github.
$ cat ~/.ssh/github.id_rsa.pub
ssh-rsa 一大串落落長的亂數= account@host
將 cat 出來的一整串文字複製貼上到
github -> account -> SSH Public Keys -> add another public key

4. ssh config 設定。
$ vi ~/.ssh/config
貼上以下文字
Host github.com
User git
Port 22
Hostname github.com
IdentityFile ~/.ssh/github.id_rsa
TCPKeepAlive yes
IdentitiesOnly yes

5. 取回 FBCE 原始碼。
在此分成兩種方法:
5.1. 如果你是 committer & have github account
$ git clone git@github.com:pigfoot/formosa.git
Initialized empty Git repository in /home/account/formosa/.git/
The authenticity of host 'github.com (65.74.177.129)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,65.74.177.129' (RSA) to the list of known hosts.
Enter passphrase for key '/home/account/.ssh/github.id_rsa': (請輸入在 Step2 所 keyin 的密碼)
remote: Counting objects: 1290, done.
remote: Compressing objects: 100% (1164/1164), done.
remote: Total 1290 (delta 616), reused 612 (delta 111)
Receiving objects: 100% (1290/1290), 1.57 MiB 619 KiB/s, done.
Resolving deltas: 100% (616/616), done.
5.2. 如果你不是 committer & have github account
http://github.com/pigfoot/formosa/tree/master click fork, 此動作會 fork 一份 code 到你自己的 Repositories. 然後再從你的帳號下載下來。
$ git clone git@github.com:你的ID/formosa.git
5.3. 如果你不是 committer & do not have github account
請直接寄 patch 給我們吧 XD

6. 確認原始碼是否有下載成功並設定基本環境。(詳細可參考:Global Git Config)
$ ls formosa/
$ git config --global github.user account
$ git config --global github.token "你的 API Token"
$ git config --global github.email "
account_AT_email"
$ git config --global color.branch auto
$ git config --global color.diff auto
$ git config --global color.interactive auto
$ git config --global color.status auto

$ git config --global user.name "YOUR NAME"
$ git config --global user.email "account_AT_email"

7. 同步更新原始碼。
$ cd formosa/
$ git fetch

Enter passphrase for key '/home/account/.ssh/github.id_rsa':
remote: Counting objects: 127, done.
remote: Compressing objects: 100% (65/65), done.
remote: Total 104 (delta 73), reused 61 (delta 39)
Receiving objects: 100% (104/104), 33.79 KiB, done.
Resolving deltas: 100% (73/73), completed with 18 local objects.
From git@github.com:pigfoot/formosa
* [new branch] login_query -> origin/login_query
70764ea..01756f2 master -> origin/master

8. 檢查 fetch 回來後的異動。
$ git status
# On branch master# Your branch is behind 'origin/master' by 20 commits, and can be fast-forwarded.
#nothing to commit (working directory clean)

9. 加入 mailing list.
http://groups.google.com/group/formosabbs


如果您有其他建議事項,歡迎來信跟我們詢問或至 bbs.CDPA.cc FormosaBBS 版反應。

歡迎您一起加入我們喔~ ^_^
Formosa BBS

延伸閱讀:How To Help FormosaBBS (二)