聚會時間公告: 因應COSCUP 2011, Kalug 8月份休會一次

三月 14, 2013

小惡魔AppleBOY
AppleBOY
小惡魔 - 電腦技術 - 工作筆記 - AppleBOY is about »

tag cloud

» Git denying non-fast forward 問題

最近幫別公司處理 denying non-fast forward 的 git server 問題,沒事就別動檔案權限,不管是不是修改內容,只要用 chmod 指令,Git 還是會判別檔案變動。處理 git push 直接給我噴

$ git push --force origin master
Total 0 (delta 0), reused 0 (delta 0)  
error: denying non-fast forward refs/heads/master (you should pull first)  
To git@git.example.com:myrepo.git  
! [remote rejected] master -> master (non-fast forward)  
error: failed to push some refs to 'git@git.example.com:myrepo.git'

會遇到這問題的原因是使用者將不該 commit 的程式碼都 push 到伺服器上面,例如資料庫帳號密碼,個人帳蜜等等,這真的是不應該,解決方式也沒有很難,只要用 git reset –hard 到您需要的 commit hash 值,並且 git push –force 方式蓋掉 Server 上面的程式碼,但是如果遇到 git push –force origingit push –force origin master 都無作用,那就請加上底下設定

$ git config --system receive.denyNonFastForwards false

在 Github 上面怎麼用 force 都可以直接覆蓋,私人自己架設的,請加入此設定,但是這設定基本上蠻危險的,如果用 git reset –hard xxxx,xxx 為很久以前的版本,並且 force 到 Server 上面,那就等於沒救了 XD,所以用 –force push 到 server 上面時,請小心阿,基本上可以搭配 git cherry-pick 來撿還需要的 commit 內容。

Ref:
git cherry-pick 處理專案 pull request
Git reset –hard and a remote repository
7.1 Customizing Git – Git Configuration

二月 8, 2013

小惡魔AppleBOY
AppleBOY
小惡魔 - 電腦技術 - 工作筆記 - AppleBOY is about »

tag cloud

» 在 git Commit 之前檢查 PHP 是否有錯誤

Git-Logo-2ColorGit-Logo-2Color

在 commit code 之前,程式設計師必須確保程式碼的正確性,包含不要放入 debug message 到 git server,寫了一個簡單的 pre-commit 程式,來確保 PHP 是否有 Parse error,或者是在寫 CoffeeScript 及 JavaScript 時,常常會用到 console.* 來當作中斷點或者是顯示變數資料,這也是需要盡量避免 commit 到伺服器,你可不想要長官 review 的時候看到這麼多 debug 訊息吧。這時候就是需要 git-hookspre-commit 幫忙檢查這些 Syntax 語法,可以直接參考我的 git-hooks 專案。安裝方式很簡單:

$ git clone https://github.com/appleboy/git-hooks.git
$ chmod +x bin/hooks.sh pre-commit
$ ./bin/hooks.sh your_project_path

如果使用 git commit 之前,就會檢查 .js、.coffee、.php 等副檔名。

一月 20, 2013

小惡魔AppleBOY
AppleBOY
小惡魔 - 電腦技術 - 工作筆記 - AppleBOY is about »

tag cloud

» CodeIgniter 台灣官網原始碼釋出

CodeIgniter

2009 年開始接觸 CodeIgniter,拿到第1版原始碼來自 中國 CodeIgniter ,版本是很舊的 1.7.x 版本,目前官方已經是 2.1.3 版本,現在朝 3.0.x 版本邁進,這次有機會將整個原始碼改寫成 3.0.x develop 分支版本,也將整個官方 source code 分享出來,讓需要原始碼範例初學者可以參考,Source Code 已經放在 github 上面,由於是拿大陸那邊的原始碼,也許有些地方寫的不是很完整,歡迎大家 pull request。

台灣 CodeIgniter Source Code Github

Related View

十二月 2, 2012
» 使用Git與Github管理軟體開發專案

之前聽聞git這個版本控制時,看到有人介紹github這個服務。 https://github.com/ http://zh-tw.whygitisbetterthanx.com/#github git是個分散式的版本控制軟體。大部分的版本控制軟體都需要一個伺服端,在commit的同時,提交到伺服器上面。git當然也可以集中管理,但是他另外多了分散管理的方式。簡單來說,billy開了一個專案,tom覺得這個專案有意思,他想玩玩看,他可以把整個repo(reoisitories)都clone過去,並且在他那邊自己有一個repo。tom可以自由的對這個repo做各種提交修改,直到他覺得滿意為止。這時候tom可以告訴billy,他改了一些什麼,若billy覺得不錯,可以從tom那邊fetch回去並merge。 由於repo可以綁在寫程式的人身上,不用一定要有中央伺服器的主從架構,

二月 6, 2012

小惡魔AppleBOY
AppleBOY
小惡魔 - 電腦技術 - 工作筆記 - AppleBOY is about »

tag cloud

» 新人 Git 版本控制教學

昨日去台北簡報如何快速學習 git,投影片主要是給新手 git 基礎介紹,如何使用 branch model,git submodule 及 tag。內容不會很難,適合之前就玩過任何一套 version control 的使用者來閱讀,如果有 svn 基礎,學習會比較輕鬆。簡報搭配 github 內容來教學。

投影片內容參考 Git Pro book 這網站教學,大家可以直接看原文說明,會更清楚 Git 使用。

Related View

十月 23, 2011

小惡魔AppleBOY
AppleBOY
小惡魔 - 電腦技術 - 工作筆記 - AppleBOY is about »

tag cloud

» Github 支援 SVN Client

Github 一年前宣佈開始支援 SVN Client,不過這是必須透過 https://svn.github.com 才可以取得資料,跟一般 git 的網址不一樣,然而就在最近宣佈了同步支援 svn 也可以存取 https://github.com/,並且過不久的將來會移除 https://svn.github.com/ 網域。

URL 處理

git 方式:

$ git clone https://github.com/appleboy/PHP-CodeIgniter-Framework-Taiwan git-ds
Cloning into git-ds...
remote: Counting objects: 4177, done.
remote: Compressing objects: 100% (665/665), done.
remote: Total 4177 (delta 3544), reused 4140 (delta 3509)
Receiving objects: 100% (4177/4177), 2.65 MiB | 239 KiB/s, done.
Resolving deltas: 100% (3544/3544), done.

svn 方式:

$ svn checkout https://github.com/appleboy/PHP-CodeIgniter-Framework-Taiwan svn-ds
A    svn-ds/branches
A    svn-ds/branches/develop
A    svn-ds/branches/develop/README
A    svn-ds/branches/develop/changelog.html
A    svn-ds/branches/develop/index.html
A    svn-ds/branches/develop/license.html
.......

官網還陸續介紹了 svn 如何在 github 上面的使用,如果對 svn 熟悉的朋友們我想也不陌生了,還沒熟悉 git 之前,我想可以先用 svn 玩 github 功能。底下是 github 打算將來支援的 svn 功能

  • 支援 branch merging 和 rebasing
  • better mapping of Subversion <=> GitHub user names in commits
  • 支援 annotate/blame
  • 讓 trunk 可以對應到 git branch 除了 master 之外

參考:
Improved Subversion Client Support

Related View

十月 17, 2011

小惡魔AppleBOY
AppleBOY
小惡魔 - 電腦技術 - 工作筆記 - AppleBOY is about »

tag cloud

» 轉移 Github 上的 Private Repository 到 BitBucket …

Bitbucket

看到 gslin 大神寫了一篇 把 GitHub 上的 private repository 搬到 BitBucket 上…,最近自己也把一些不能公開的專案轉到 BitBucket 上面,由於在 BitBucket 上面可以無限開 private repository,所以我想也沒有必要付費給 Github,雖然論 Web 功能上而言,Github 還是略勝一籌,個人還是比較習慣 github 有 Network 的圖形可以看,不過平常還是都是在打指令,所以也沒差了,在 push 速度上面,感覺 BitBucket 也沒有輸 github 許多,所以決定就轉過去了,人總是為了錢所考量,當然 BitBucket 還是有些缺點的,可以參考之前寫的 Bitbucket 開始支援 Git Repository

底下介紹兩種方式來轉移 Github 的 Repo 到 BitBucket:

透過 BitBucket 提供的 tool

只要把 github 上的 Repository 網址複製下來,透過 BitBucket import tool 介面來轉換就可以了,這方法比較簡單懶人,如果你熟悉 git 的操作,就可以透過第二種方法來弄。

透過 git push

先在 BitBucket 建立一個空的 private repo,之後把網址複製,打開原本 clone 下來的專案 .git/config,將 url 換成剛剛建立的 repo url 即可。接著打入底下指令去 push 即可。

$ git push origin master

當然如果你有很多 branch 的話,請重複上面步驟即可。

Related View

十月 4, 2011

小惡魔AppleBOY
AppleBOY
小惡魔 - 電腦技術 - 工作筆記 - AppleBOY is about »

tag cloud

» Bitbucket 開始支援 Git Repository

Bitbucket

很高興剛剛收到 Bitbucket 寄來一封會員信,標題非常吸引大家的注意,那就是 Bitbucket now rocks Git.,是的,你沒看錯,Bitbucket 現在開始支援 Git repository,不再只有 Mercurial 可以使用,這還不算什麼,Bitbucket 更是推出無限制免費 private repos for free ,這樣的推出,不知道會有多少 Github 用戶轉移到 Bitbucket 上面,還有另一項主因就是 Unlimited disk space 無限制硬碟容量,不過也許不用高興的太早,Bitbucket 在使用者人數上面有些限制,可以參考 Plans & Pricing,免費方案每個 Repository 只能有5個 User,反觀 Github 並沒有這限制,不過我想這也不是問題,大家可以 Fork 到自己的專案,在 Pull Request 即可。

補充官方網站提供了轉換各大 Source Hosting 工具,目前支援 GithubSourceForgeGoogle CodeSubversionMercurial…等。

Related View

九月 22, 2011

小惡魔AppleBOY
AppleBOY
小惡魔 - 電腦技術 - 工作筆記 - AppleBOY is about »

tag cloud

» Git Submodule 介紹與使用

自己用 Git 已經很長一段時間了,沒用過 git submodule 的話真的是對不起自己,今天來筆記 Git Submodule 一些操作步驟及說明。

git Submodule 使用時機

大家在開發新專案的時候,不知道有沒有用到其他專案的程式碼,像是 Web 專案,也許會用到 Blueprintcss CSS Framwork 或者是 Sass,這些專案目前都放在 Github 上面進行維護,以前的作法就是先 git clone 下來,把要的檔案分別複製到自己專案,可是問題來了,如果官方更新了程式碼,那自己的專案如何更新呢?難道是重複步驟把檔案複製到原來地方嗎?這樣會不會太麻煩,這時候就是需要 git submodule 來幫助大家進行程式碼的更新,這樣隨時隨地都可以取得最新的程式碼。補充說明一點,git 目前無法針對單一專案底下的單一檔案或目錄進行 clone,而必須 clone 整個目錄,這點跟 svn 有很大的不同,所以 git 可以建立各個不同的 submodule 來整合成一個大型 Project。換句話說就是: 在您的專案底下,你可以任意將其他人的專案掛載在自己任何目錄底下

建立 Git Submodule

在練習 git 指令之前請先註冊好 github 帳號,並且開一個測試 repository,建立 Submodule 非常容易,範例如下:

git submodule add <repository> [<path>]

實際指令範例:

git submodule add https://github.com/appleboy/CodeIgniter-TW-Language user_guide

下這指令之前請注意最後面的 path 部份,請勿先建立空的目錄,也就是如果該目錄存在,就會衝突,所以並不需要額外幫 module 建立目錄,指令完成結果如下:

Cloning into user_guide...
remote: Counting objects: 32, done.
remote: Compressing objects: 100% (19/19), done.
remote: Total 32 (delta 12), reused 32 (delta 12)
Unpacking objects: 100% (32/32), done.

這時候在目錄底下打入指令 git status,你會發現多了兩個檔案需要 commit

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       new file:   .gitmodules
#       new file:   user_guide
#

注意第一個檔案 .gitmodules,裡面紀錄 submodule 的對應關係,我們實際打開看內容:

[submodule "user_guide"]
    path = user_guide
    url = https://github.com/appleboy/CodeIgniter-TW-Language

裡面寫的很清楚,之後如果要清除 sub module 也是要從這檔案移除相關設定,接著就是直接 commit 到 project 底下吧

git commit -a -m "first commit with submodule codeigniter user guide" && git push

接著回去看 github 網站就會多出一個小圖示了
git_submodule
最後還是需要初始化 init submodule,透過底下指令來達成,否則 git 不知道你有新增 module

git submodule init

clone project with Git Submodule

我們還是拿上面的例子來測試,首先還是一樣用 git clone 來下載程式碼:

git clone git@github.com:appleboy/test.git test2

可是你有沒有發現 user_guide 這 sub module 是空目錄,這時候就是要透過 git submodule 來下載程式碼

[freebsd][root][ /home/git/test2 ]# git submodule init
Submodule 'user_guide' (https://github.com/appleboy/CodeIgniter-TW-Language) registered for path 'user_guide'
[freebsd][root][ /home/git/test2 ]# git submodule update
Cloning into user_guide...
remote: Counting objects: 32, done.
remote: Compressing objects: 100% (19/19), done.
remote: Total 32 (delta 12), reused 32 (delta 12)
Unpacking objects: 100% (32/32), done.
Submodule path 'user_guide': checked out '7efead6378993edfaa0c55927d4a4fdf629c4726'

注意上面,有沒有看到 git submodule init 來設定 .git/config,在接著用 git submodule update 來更新檔案,可以打開 .git/config 可以發現多了底下資料:

[submodule "user_guide"]
    url = https://github.com/appleboy/CodeIgniter-TW-Language

更新已安裝 module

一樣切換到 sub module 目錄,接著做 git pull

cd user_guide/
git pull origin master

這時候我們切回去上層目錄,執行 git status

# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   user_guide (new commits)

我們有了 new commit,有沒有發現與 git submodule add 的時候一樣,這時候我們需要同步 sub module commit ID 到 parent,所以一樣執行 git commit && git push 即可。

git commit -a -m "first commit with submodule codeigniter user guide" && git push

最後可以透過 statu 來看看是否有相同的 commit ID

git submodule status

移除 Sub module

移除方式非常容易,上面有提到的檔案都必需要經過修改

1. 移除目錄

git rm --cached [目錄]
git rm [目錄]

2. 修改 .gitmodules,移除不需要的 module

vi .gitmodules

3. 修改 .git/config,移除 submodule URL

vi .git/config

4. 執行 commit

git add . && git commit -m "Remove sub module"

5. 最後 syn module 資料

git submodule sync

總結歸納

git submodule 可以用在跟其他團隊一起合作開發時候,我們只需要知道大的 git,一些細部的 sub module 就可以讓其他團隊在繼續往下開,相當方便。另外也避免每當要更新檔案的時候,還需要重複 clone 加上 cp 資料到對應目錄。

Reference:
Git Submodule 的認識與正確使用!
Pro git: git submodule

Related View

八月 22, 2011

小惡魔AppleBOY
AppleBOY
小惡魔 - 電腦技術 - 工作筆記 - AppleBOY is about »

tag cloud

» CodeIgniter 轉移版本控制到 Github 順便 Release 2.0.3

CodeIgniter

在我上禮拜 8/20,8/21 參加 COSCUP 2011 會議的時候,CodeIgniter 偷偷 Release 了 2.0.3 版本,也不算偷偷 Release,因為剛好8月20,21號也是 CICON 2011 會議,CodeIgniter 想給來聽演講的學員們一個驚喜吧,也因為這個 CodeIgniter Con 2011 會議,官方也宣佈將轉換版本控制,原本放在 bitbucket 的程式碼也都轉換到 Github 上面了,另外順便把 CodeIgniter Reactor 取消後面 Reactor 字串,改成 CodeIgniter 了,那 Reactor 呢,就變成 Develop 分支,這個消息真的是太棒了,轉換到大家所熟悉的 Git 版本控制,有些常常在貢獻程式碼的開發者,都是在使用 Github。不管是不是 CodeIgniter,其他許多 opensource 包含 jQuery, phpBB…等都是在使用 github。


直接下載 2.0.3 玩看看吧

參考:
繁體中文 CodeIgniter 官方公告

Related View

A Feedjack powered Planet
A Django site.